Advertisement
Guest User

Untitled

a guest
Mar 13th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. const dispatcher = require('./dispatcher')
  4. const express = require('express'),
  5. bodyParser = require('body-parser'),
  6. // morgan = require('morgan'),
  7. db = require('./config/db.js'),
  8. env = require('./config/env'),
  9. router = require('./router/index');
  10.  
  11. const app = express();
  12. const PORT = env.PORT;
  13. dispatcher.start()
  14.  
  15. // app.use(morgan('combined'));
  16. app.use(bodyParser.json());
  17.  
  18. app.use((req, res, next) => {
  19.   res.header('Content-Type', 'application/json');
  20.   res.header("Access-Control-Allow-Origin", "*");
  21.   next();
  22. });
  23.  
  24. router(app, db);
  25.  
  26. //drop and resync with { force: true }
  27. db.sequelize
  28. .authenticate()
  29. .then(()=> {
  30.     console.log("Connection has been established successfully.");
  31.       // event handling:
  32.       db.sequelize.sync()
  33.         .then(() => {
  34.           console.log("Synced");
  35.         })
  36.         .catch(error => {
  37.           console.log("Not synced : " + error);
  38.         });
  39.         app.listen(PORT, () => {
  40.             console.log('Express listening on port:', PORT);
  41.           });
  42.     })
  43.     .catch(err => {
  44.         console.error("Unable to connect to the database:", err);
  45.       });
  46.       module.exports = app
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement