-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
64 lines (54 loc) · 1.96 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var express = require('express');
var cors = require('cors');
var router = express.Router();
var session = require('express-session');
var morgan = require('morgan');
var bodyParser = require('body-parser');
var multipart = require('connect-multiparty');
var path = require('path');
var fs = require('fs');
var uuid = require('node-uuid');
var mkdirp = require('mkdirp');
var log4js_wrapper = require('./utils/log4js_wrapper.js');
require('date-utils');
// load config
global.PROJECT_CONFIG = require('./config/projectConfig.json');
var fileLogger = log4js_wrapper.start(global.PROJECT_CONFIG.name);
global.LOG = fileLogger;
var app = express();
var httpLogger = morgan('tiny', { skip: function (req, res) { return res.statusCode < 400; }, stream: { write: function (str) { fileLogger.debug(str.trim()); } } });
app.use(httpLogger);
app.use(session({
secret: uuid.v1(),
name: global.PROJECT_CONFIG.name,
resave: false,
saveUninitialized: true
}));
app.use(bodyParser.json({limit: '30mb'}));
app.use(bodyParser.urlencoded({ limit: '30mb', extended: false, parameterLimit: 1000 }));
app.use(multipart());
app.use(cors({
origin: ['http://localhost:3001','http://localhost:3006','http://localhost:8080']
}));
// 시작 기준 페이지
router.get('/', function (req, res, next) {
req.session.destroy(function (err) {
if (!err) {
res.sendFile(path.join(__dirname+'/public/index.html'));
}
});
});
app.use('/', router);
app.use('/api', require('./routes/api.js'));
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'node_modules')));
app.use('/data', express.static(path.join(__dirname, 'data')));
var port = process.env.PORT || 3000;
var server = app.listen(port, function () {
global.LOG.debug('Express server has started on port ' + port);
});
server.timeout = 600000;
process.on('uncaughtException', function (err) {
//예상치 못한 예외 처리
global.LOG.error(err);
});