main.js 910 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/bin/node
  2. const path = require('path');
  3. const fs = require('fs');
  4. const Router = require('node-simple-router');
  5. const http = require('http');
  6. const CONFIG = require('./src/config.js');
  7. const RouterUtils = require('./src/routerUtils.js').RouterUtils;
  8. function App() {
  9. this.router = new Router({ static_route: __dirname+"/static/" });
  10. const _app = this;
  11. this.routerUtils = new RouterUtils(this);
  12. this.databaseHelper = require('./src/databaseHelper.js').DatabaseHelper;
  13. }
  14. App.prototype.init = async function() {
  15. const _app = this;
  16. require('./router/mdi.js').register(this);
  17. await this.databaseHelper.init();
  18. }
  19. App.prototype.clock = function() {
  20. setTimeout(() => this.clock(), 10 *60 *1000); // 10 minutes
  21. }
  22. App.prototype.run = function() {
  23. this.clock();
  24. http.createServer(this.router).listen(CONFIG.port);
  25. }
  26. let app = new App();
  27. app.init().then(() => app.run());