-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
90 lines (60 loc) · 2.64 KB
/
app.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* Ö÷Îļþ app.js
*/
var express = require('express');
var http = require('http');
//var https = require('https');
var path = require('path');
var fs = require('fs');
var logger = require('morgan');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var methodOverride = require('method-override');
var errorhandler = require('errorhandler');
var router = require('./routes/router'); // App µÄ×Ô¶¨Òå·ÓÉÐÅÏ¢
var AppConfig = require('./app-config.json'); // AppConfig
var app = express();
// ==================== App ÉèÖÃ ====================
app.set('port', AppConfig.server.server_port); // ¶Ë¿ÚÉèÖÃ
app.set('views', path.join(__dirname, 'views')); // ÉèÖÃÊÓͼ View ËùÔڵķ¾¶
app.set('view engine', 'ejs'); // html Ä£°åÒýÇæ
// ==================== Öмä¼þÉèÖÃ(˳ÐòºÜÖØÒª) ====================
app.use(logger('dev')); // ¿ª·¢ÈÕÖ¾
// ·ÃÎÊÈÕÖ¾
// var access_log_file = fs.createWriteStream('./log/access_log.log', { flags: 'a', encoding: 'utf8' }); // ·ÃÎÊÈÕÖ¾Îļþ
// app.use(express.logger({stream: access_log_file}));
//app.use(express.favicon(path.join(__dirname, 'public/images/favicon.ico'))); // favicon ·¾¶
// app.use(express.bodyParser()); // ²»¼æÈÝÎļþÉÏ´«
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
app.use(cookieParser());
app.use(session({secret: 'sessiontest'}));
app.use(methodOverride());
app.use(express.static(path.join(__dirname, 'public'))); // ¾²Ì¬ (images + css + js + fonts) ×ÊÔ´ËùÔڵķ¾¶ (¿ÉÒÔÉèÖöà¸ö)
//app.use(app.router);
if ('development' == app.get('env')) { // ¿ª·¢»·¾³ÏµĴíÎó´¦Àí
app.use(errorhandler());
}
// ==================== ×Ô¶¨Òå·ÓÉÐÅÏ¢ ====================
router.map(app);
// ==================== ´´½¨ http ·þÎñÆ÷ ====================
http.createServer(app).listen(app.get('port'), function(){
console.log('doc4doc app server listening on port ' + app.get('port'));
});
// ==================== ´´½¨ https ·þÎñÆ÷ ====================
/*
var options = {
key: fs.readFileSync('./cert/private.key'),
cert: fs.readFileSync('./cert/certificate.crt')
};
https.createServer(options, app).listen(app.get('port'), function(){
console.log('antark server listening on port ' + app.get('port'));
});
app.use((req, res, next) => {
if (req.protocol === 'http') {
return res.redirect(301, `https://${req.headers.host}${req.url}`);
}
next();
});
*/