Advertisement
rodrigofbm

Untitled

Apr 18th, 2018
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express = require('express');
  2. const bodyParser = require('body-parser');
  3. const consign = require('consign');
  4. const expressValidator = require('express-validator');
  5. const multiparty = require('connect-multiparty');
  6. const cors = require('cors');
  7.  
  8. const app = express();
  9.  
  10.  
  11. app.use(bodyParser.json())
  12. app.use(bodyParser.urlencoded({extended: false}));
  13. app.use(expressValidator());
  14. app.use(multiparty());
  15.  
  16. app.use(function(req, res, next) {
  17.     res.header("Access-Control-Allow-Origin", "*");
  18.     res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
  19.     res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  20.     next();
  21. });
  22.  
  23. /*app.use( (req, res, next) => {
  24.     // Website you wish to allow to connect
  25.     res.setHeader('Access-Control-Allow-Origin', '*');
  26.  
  27.     // Request methods you wish to allow
  28.     res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
  29.  
  30.     // Request headers you wish to allow
  31.     res.setHeader('Content-Type', 'application/json');
  32.  
  33.     // Set to true if you need the website to include cookies in the requests sent
  34.     // to the API (e.g. in case you use sessions)
  35.     res.setHeader('Access-Control-Allow-Credentials', true);
  36.  
  37.     // Pass to next layer of middleware
  38.     next();
  39.   });
  40. */
  41. consign()
  42.     .include('./app/routers')
  43.     .then('./app/controllers')
  44.     .then('./app/models/Schemas')
  45.     .then('./config/dbConnection.js')
  46.     .then('./app/models')
  47.     .into(app);
  48.  
  49. module.exports = app;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement