Commit 9db39b85a0c787df33e0f57584a74c86f98c779d

Authored by Adhidarma Hadiwinoto
1 parent 65d9491e7d
Exists in master

typo

Showing 1 changed file with 1 additions and 1 deletions Inline Diff

1 var express = require('express'); 1 var express = require('express');
2 var nunjucks = require('nunjucks'); 2 var nunjucks = require('nunjucks');
3 var bodyParser = require('body-parser'); 3 var bodyParser = require('body-parser');
4 4
5 var config; 5 var config;
6 var logger; 6 var logger;
7 7
8 var app = express(); 8 var app = express();
9 9
10 function pageHome(req, res, next) { 10 function pageHome(req, res, next) {
11 res.render('restart.html', {title: config.globals.smsc}); 11 res.render('restart.html', {title: config.globals.smsc});
12 } 12 }
13 13
14 function doRestart(req, res, next) { 14 function doRestart(req, res, next) {
15 if (config.webadmin.password.trim() && config.webadmin.password.trim() == req.body.password) { 15 if (config.webadmin.password.trim() && config.webadmin.password.trim() == req.body.password) {
16 res.end('Restarting'); 16 res.end('Restarting');
17 process.exit(1); 17 process.exit(1);
18 } else { 18 } else {
19 res.redirect('/'); 19 res.redirect('/');
20 } 20 }
21 } 21 }
22 22
23 function init(options) { 23 function init(options) {
24 config = options.config; 24 config = options.config;
25 logger = options.logger; 25 logger = options.logger;
26 26
27 app.set('views', './views'); 27 app.set('views', './views');
28 app.use(express.static('public', {maxAge: 24 * 3600 * 1000})); 28 app.use(express.static('public', {maxAge: 24 * 3600 * 1000}));
29 app.use(bodyParser.urlencoded({extended: true})); 29 app.use(bodyParser.urlencoded({extended: true}));
30 nunjucks.configure('views', { 30 nunjucks.configure('views', {
31 autoescape: true, 31 autoescape: true,
32 express: app 32 express: app
33 }); 33 });
34 34
35 app.get('/', pageHome); 35 app.get('/', pageHome);
36 app.post('/', doRestart); 36 app.post('/', doRestart);
37 37
38 app.listen(config.webadmin.listen_port, function () { 38 app.listen(config.webadmin.listen_port, function () {
39 logger.info('Webadmin listening on port ' + config.webadmin.listen_port); 39 logger.info('Webadmin listening on port ' + config.webadmin.listen_port);
40 } 40 });
41 }); 41 });
42 42
43 exports.init = init; 43 exports.init = init;
44 44
45 } 45 }
46 46