[TIC-Web] add boilerplate
[archive/20170607/tools/tic.git] / app.js
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.1 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 var express = require('express');
18 var session = require('express-session');
19 var path = require('path');
20 var bodyParser = require('body-parser');
21 var JL = require('jsnlog').JL;
22 var jsnlog_nodejs = require('jsnlog-nodejs').jsnlog_nodejs;
23 var logger = JL('app.js');
24 var AppConfig = require('./config.json');
25
26
27 var app = express();
28 /* app config */
29 app.set('port', process.env.PORT || AppConfig.TIC_WEB.PORT);
30 app.use(bodyParser.json());
31 app.use(bodyParser.urlencoded({extended: true}));
32 app.use(express.static(path.join(__dirname, '/public/src'))); //module directory
33
34 var server = require('./controller/server').start(app);
35 var io = require('./controller/socketio').listen(server);
36 var router = require('./controller/router').init(server);
37
38 app.use(session({
39     secret: 'tic',
40     resave: false,
41     saveUninitialized: true
42 }));
43
44 app.use('/api', router);
45
46 /**
47  * jsnlog.js on the client by default sends log messages to /jsnlog.logger, using POST.
48  * @URI /*.logger
49  * @TYPE POST
50  */
51 app.post('*.logger', function (req, res) {
52     // Pass the log messages to the server side jsnlog.js
53     jsnlog_nodejs(JL, req.body);
54
55     // Send empty response. This is ok, because client side jsnlog does not use response from server.
56     res.send('');
57 });