[TIC-Web] Bug fixed. the problem that paging
[archive/20170607/tools/tic.git] / app.js
diff --git a/app.js b/app.js
index 652408a..5be94ea 100644 (file)
--- a/app.js
+++ b/app.js
@@ -1,41 +1,57 @@
-var http = require('http');
-var path = require('path');
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 
-var socketio = require('socket.io');
-var fs = require('fs');
 var express = require('express');
+var session = require('express-session');
+var path = require('path');
 var bodyParser = require('body-parser');
+var JL = require('jsnlog').JL;
+var jsnlog_nodejs = require('jsnlog-nodejs').jsnlog_nodejs;
+var logger = JL('app.js');
+var AppConfig = require('./config.json');
 
-var app = express();
-var server = http.createServer(app);
-var io = socketio.listen(server);
 
-/* FIXME: change port
-   @author: leechwin.lee@samsung.com
- */
-app.set('port', process.env.PORT || 3000);
+var app = express();
+/* app config */
+app.set('port', process.env.PORT || AppConfig.TIC_WEB.PORT);
 app.use(bodyParser.json());
-app.use(bodyParser.urlencoded());
+app.use(bodyParser.urlencoded({extended: true}));
+app.use(express.static(path.join(__dirname, '/public/src'))); //module directory
 
-app.use(express.static(path.join(__dirname, '/public/src')));
+var server = require('./controller/server').start(app);
+var io = require('./controller/socketio').listen(server);
+var router = require('./controller/router').init(server);
 
-server.listen(app.get('port'),  process.env.IP || "0.0.0.0", function(){
-    var addr = server.address();
-    console.log('Server listening at', addr.address + ':' + addr.port);
-});
+app.use(session({
+    secret: 'tic',
+    resave: false,
+    saveUninitialized: true
+}));
 
-/* server - socket test
-   TODO: server side logic
-   - fs controllers(read/create)
-   - connection with MIC
+app.use('/api', router);
+
+/**
+ * jsnlog.js on the client by default sends log messages to /jsnlog.logger, using POST.
+ * @URI /*.logger
+ * @TYPE POST
  */
-io.on('connection', function (socket) {
-    console.log('socket connection');
-
-    socket.on('disconnect', function () {
-        console.log('socket disconnect');
-    });
-    socket.on('message', function (msg) {
-        console.log('socket message');
-    });
+app.post('*.logger', function (req, res) {
+    // Pass the log messages to the server side jsnlog.js
+    jsnlog_nodejs(JL, req.body);
+
+    // Send empty response. This is ok, because client side jsnlog does not use response from server.
+    res.send('');
 });