-
Notifications
You must be signed in to change notification settings - Fork 4
/
wechatauth.js
70 lines (57 loc) · 1.76 KB
/
wechatauth.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
//server.js
//BASE SETUP
//====================================
//call the packages we need
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var morgan = require('morgan');
var fs = require('fs');
var path = require('path');
var fileStreamRotator = require('file-stream-rotator');
var cookieParser = require('cookie-parser');
//call routers modules
var indexRouter = require('./routers/index');
//LOG
var logDir = path.join(__dirname, 'logs');
//ensure log directory exists
fs.existsSync(logDir) || fs.mkdirSync(logDir);
//create a rotating write stream
var accessLogStream = fileStreamRotator.getStream({
date_format: 'YYYYMMDD',
filename: path.join(logDir, 'access-%DATE%.log'),
frequency: 'daily',
verbose: true
});
//APP CONFIG
//====================================
//configure app to use BodyParser();
//this will let us get the data form a POST
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(cookieParser());
//log module
app.use(morgan('short'));
app.use(morgan('combined', {
stream: accessLogStream
}));
var port = process.env.PORT || 8091; //set port
app.use(express.static('app'));
//REGISTER OUR ROUTES
//===================================
app.use('/', indexRouter);
//ERROR HANDLE
app.use(function(req, res, next){
var err = new Error('not Found');
err.status = 404;
res.status(404).send(err);
});
app.use(function(err, req, res, next) {
console.error(err.stack);
res.status(500).send('Something broke!');
});
//START THE SERVER
//====================================
app.listen(port, function(){
console.log('server is listening to port ' + port);
});