Can anyone help me with this issue ? I am stuck on this for 2 days,....I really do not how to fix it....I built a web page(contains a table) using angular cli/angular5 and expressjs. I use mongoose mongodb as the database. Everything working fine on local. But When I uploaded the dist folder and deployed it to the azure web app, its table is empty. The error log looks like this:
Here is my temp website:"https://stringfr.azurewebsites.net". you can check the full error log by inspect.
I think this is something to do with this line in the book.component.ts. Here I get data from the database and use it on a simple html table. Note book_value is just a interface for me to a get a more structural data.
this.http.get<book_value>('/book').subscribe ( data => this.books = data );
Here is where I init the '/book'. in app.js
var express = require('express'); var path = require('path'); var logger = require('morgan'); var bodyParser = require('body-parser'); var book = require('./routes/book'); var app = express(); var mongoose = require('mongoose'); mongoose.Promise = require('bluebird'); //mongoose.connect('put ur own mongodb') // .then(() => console.log('connection succesful')) //.catch((err) => console.error(err)); mongoose.connect('mongodb://localhost/mean-angular5') .then(() => console.log('connection succesful')) .catch((err) => console.error(err)); app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({'extended':'false'})); app.use(express.static(path.join(__dirname, 'dist'))); app.use('/books', express.static(path.join(__dirname, 'dist'))); app.use('/book', book);
In the ./routes/book.js
var express = require('express'); var router = express.Router(); var mongoose = require('mongoose'); var Book = require('../models/Book.js'); /* GET ALL BOOKS */ router.get('/', function(req, res, next) { Book.find(function (err, products) { if (err) return next(err); res.json(products); console.log(products); console.log("products info above"); console.log(res); }); });
Here is my schema in the ../models/Book.js:
var mongoose = require('mongoose'); var BookSchema = new mongoose.Schema({ timestamp: String, question : String, answer : String }); module.exports = mongoose.model('Book',BookSchema );
Since I am using dist folder. I use this web.config.
Note: There is not error showing on the azure log stream. Here is my app.module:
const appRoutes: Routes = [ { path: 'books', component: BookComponent, data: { title: 'Book List' } }, { path: '', redirectTo: '/books', pathMatch: 'full' } ]; @NgModule({ declarations: [ AppComponent, BookComponent, ], imports: [ BrowserModule, HttpClientModule, CalendarModule, BrowserAnimationsModule, FormsModule, AccordionModule, PanelModule, ButtonModule, RadioButtonModule, DataTableModule, MultiSelectModule, DropdownModule, RouterModule.forRoot( appRoutes, { enableTracing: true } // <-- debugging purposes only ) ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }