ThierryDD
4/16/2018 - 6:48 AM

Minimal server.js

Combining both Angular the Web Application and the JSON Mockup Server

const path = require('path');
const jsonServer = require('json-server')
const data = require('./server.json')

const app = jsonServer.create()
const port = process.env.PORT || 3000

const router = jsonServer.router(data, {foreignKeySuffix: '_id'})
router.db._.id = '_id';

app.use(jsonServer.defaults({
    logger: process.env.NODE_ENV !== 'production',
    static: path.join(__dirname, '../../dist')
}))

app.use(router)

app.listen(port, () => {
  console.log('JSON Server listening on http://localhost:' + port)
})