-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
46 lines (32 loc) · 1.15 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
var express = require('express'),
fs = require('fs');
path = require('path'),
conf = require('./conf.js'),
//multer = require('multer'),
ejs = require('ejs');
var app = express();
var bodyParser = require('body-parser');
var jsonParser = bodyParser.json();
var urlencodedParser = bodyParser.urlencoded({ extended: false });
var errorLogfile = fs.createWriteStream('error.log', {flags: 'a'});
app.engine('.html', ejs.renderFile);
app.set('etag', 'strong');
app.set('view engine', 'html');
app.set('views', path.join(__dirname, '/views'));
app.use(express.static(path.join(__dirname, '/public')));
app.use(express.static(path.join(__dirname, '/download')));
// app.use(multer({ dest: './uploads/'}));
app.use(jsonParser);
// 缺少这个,会导致 req.body = {}
app.use(urlencodedParser);
// cookie
var cookieParser = require('cookie-parser');
app.use(cookieParser());
app.use(require('./routes'));
// app.use(function(err, req, res, next) {
// var meta = '[' + new Date() + '] ' + req.url + '\r\n';
// errorLogfile.write(meta + err.stack + '\r\n');
// res.status(500).send({error: 'something blew up!'});
// req.end();
// });
app.listen(conf.port);