main.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const express = require('express');
  2. const session = require('express-session');
  3. const routes = require('./routes/index');
  4. const passportSetup = require('./services/passport-setup');
  5. const mysql = require('mysql');
  6. const bodyParser = require('body-parser');
  7. const app = express();
  8. const parseToken = require('./middlewares/author.js');
  9. const passport = require('passport');
  10. const FileService = require('./services/FileService');
  11. app.use(bodyParser.json({limit: '10mb'}));
  12. app.use(function(req,res,next){
  13. res.header('Access-Control-Allow-Origin','*');
  14. res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
  15. res.header('Access-Control-Allow-Headers', 'Content-Type, token');
  16. next();
  17. })
  18. app.use(express.static('front-end'));
  19. app.use(parseToken);
  20. app.use(passport.initialize());
  21. app.use(passport.session());
  22. app.use('/users',routes.User);
  23. app.use('/globals',routes.Globals);
  24. app.use('/products',routes.Products);
  25. app.use('/categories',routes.Categories);
  26. app.use('/orders',routes.Orders);
  27. app.use('/shipping',routes.Shipping);
  28. app.use('/payment',routes.Payment);
  29. app.use('/auth',routes.AuthRoutes);
  30. app.use('/profile',routes.Profile);
  31. app.use('/fileupload',FileService.router);
  32. //app.use('/braintree',routes.Braintree);
  33. app.use(function(err,req,res,next){
  34. res.status(422).send({error:err.message});
  35. });
  36. app.listen(5000,function(){
  37. console.log('now listening to requests');
  38. });