[TIC-Web] Apply generic resource pooling
[archive/20170607/tools/tic.git] / app.js
1 var express = require('express');
2 var session = require('express-session');
3 var path = require('path');
4 var bodyParser = require('body-parser');
5 var JL = require('jsnlog').JL;
6 var jsnlog_nodejs = require('jsnlog-nodejs').jsnlog_nodejs;
7 var logger = JL('app.js');
8 var AppConfig = require('./config.json');
9
10
11 var app = express();
12 /* app config */
13 app.set('port', process.env.PORT || AppConfig.TIC_WEB.PORT);
14 app.use(bodyParser.json());
15 app.use(bodyParser.urlencoded({extended: true}));
16 app.use(express.static(path.join(__dirname, '/public/src'))); //module directory
17
18 var server = require('./controller/server').start(app);
19 var io = require('./controller/socketio').listen(server);
20 var router = require('./controller/router').init(server);
21
22 app.use(session({
23     secret: 'tic',
24     resave: false,
25     saveUninitialized: true
26 }));
27
28 app.use('/api', router);
29
30 /**
31  * jsnlog.js on the client by default sends log messages to /jsnlog.logger, using POST.
32  * @URI /*.logger
33  * @TYPE POST
34  */
35 app.post('*.logger', function (req, res) {
36     // Pass the log messages to the server side jsnlog.js
37     jsnlog_nodejs(JL, req.body);
38
39     // Send empty response. This is ok, because client side jsnlog does not use response from server.
40     res.send('');
41 });