app.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. var createError = require('http-errors');
  2. var express = require('express');
  3. var path = require('path');
  4. var cookieParser = require('cookie-parser');
  5. var logger = require('morgan');
  6. const knex = require('knex');
  7. var app = express();
  8. var RoutingSystem = require('./systems/RoutingSystem');
  9. var RepositorySystem = require('./systems/RepositorySystem').setDB();
  10. var AdminSystem = require('./systems/AdminSystem');
  11. var UserSystem = require('./systems/UserSystem');
  12. var ModuleSystem = require('./systems/ModuleSystem');
  13. var Filters = require('./modules/Filters/FilterService');
  14. ModuleSystem.loadModules();
  15. ModuleSystem.run();
  16. app.use(express.json({limit: '50mb'}));
  17. app.set('view engine', 'html');
  18. // app.use(logger('dev'));
  19. // app.use(express.urlencoded({ extended: false }));
  20. // app.use(cookieParser());
  21. // app.use(express.static(path.join(__dirname, 'public')));
  22. app.use(UserSystem.Middleware);
  23. app.use(Filters.Middleware);
  24. app.use(RoutingSystem.router);
  25. // catch 404 and forward to error handler
  26. app.use(function(req, res, next) {
  27. next(createError(404));
  28. });
  29. // error handler
  30. app.use(function(err, req, res, next) {
  31. // set locals, only providing error in development
  32. if(err.message !== "401")
  33. throw err;
  34. res.locals.message = err.message;
  35. res.locals.error = req.app.get('env') === 'development' ? err : {};
  36. // render the error page
  37. res.sendStatus(err.status || 500);
  38. //res.sendStatus(404);
  39. });
  40. module.exports = app;