| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #!/bin/node
- const path = require('path');
- const fs = require('fs');
- const Router = require('node-simple-router');
- const http = require('http');
- const CONFIG = require('./src/config.js');
- const RouterUtils = require('./src/routerUtils.js').RouterUtils;
- const ClockWatch = require('./src/clockwatch.js').ClockWatch;
- function App() {
- this.router = new Router({ static_route: __dirname+"/static/" });
- const _app = this;
- this.routerUtils = new RouterUtils(this);
- this.databaseHelper = require('./src/databaseHelper.js').DatabaseHelper;
- this.dataDir = __dirname+'/data/';
- }
- App.prototype.getData = function(privId) {
- return path.join(this.dataDir, privId);
- }
- App.prototype.init = async function() {
- if (!fs.existsSync(this.dataDir))
- fs.mkdirSync(this.dataDir);
- require('./router/mdi.js').register(this);
- require('./router/input.js').register(this);
- require('./router/qrcode.js').register(this);
- await this.databaseHelper.init();
- }
- App.prototype.clock = async function() {
- await ClockWatch.tick(this);
- setTimeout(async () => await this.clock(), 10 *60 *1000); // 10 minutes
- }
- App.prototype.run = function() {
- this.clock();
- http.createServer(this.router).listen(CONFIG.port);
- }
- let app = new App();
- app.init().then(() => app.run());
|