forked from liuxiaodong/wechat-iot-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
55 lines (46 loc) · 1.28 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
var path = require('path');
var express = require('express');
var morgan = require('morgan');
var weixin = require('./util/weixin');
var app = express();
app.set('port', process.env.PORT || 3000);
app.use(morgan('dev'));
app.use(express.static(path.join(__dirname, 'public')));
app.set('views', __dirname + '/public/views');
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.use(require('weixin-body-parser')());
// 微信公众号配置的URL 路由
app.use('/wechat', weixin.trap);
// H5页面需要的接口(获取签名)
require('./route/handle')(app);
// H5 的demo页面
app.get('/*', function(req, res, next){
res.render('index');
});
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
/* jshint unused:false */
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.json({
env: 'development',
message: err.message,
error: err
});
});
}
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.json({
message: err.message,
error: {}
});
});
var server = app.listen(app.get('port'), function(a, b){
console.log('weixin server listening on port ' + server.address().port);
});