-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·61 lines (50 loc) · 1.66 KB
/
app.js
File metadata and controls
executable file
·61 lines (50 loc) · 1.66 KB
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
//基础配置
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var proxy = require('express-http-proxy');
var hbs = require('hbs');
//引入session模块
var session = require('express-session');
var app = express();
//配置服务器代理 解决跨域问题
app.use('/api', proxy('www.***.com'));
//配置session
app.use(session({
secret: 'myhhhhhhhhhhhhhheedesecret',
resave: true,
saveUninitialized:false,
cookie: { maxAge: 60 * 30 * 1000 }
}));
// view engine setup
//配置hbs模板
app.set('views', path.join(__dirname, 'views'));
app.engine('html', hbs.__express);
app.set('view engine', 'html');
//类似于include的配置
hbs.registerPartials(__dirname + '/views/partials');
var blocks = {};
hbs.registerHelper('extend', function(name, context) {
var block = blocks[name];
if (!block) {
block = blocks[name] = [];
}
block.push(context.fn(this)); // for older versions of handlebars, use block.push(context(this));
});
hbs.registerHelper('block', function(name, context) {
var len = (blocks[name] || []).length;
var val = (blocks[name] || []).join('\n');
blocks[name] = [];
return len ? val : context.fn(this);
});
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'static')));
module.exports = app;