|
@@ -12,22 +12,26 @@ if (config.useOneapm) { |
|
@@ -12,22 +12,26 @@ if (config.useOneapm) { |
12
|
require('oneapm');
|
12
|
require('oneapm');
|
13
|
}
|
13
|
}
|
14
|
|
14
|
|
15
|
-let express = require('express'),
|
|
|
16
|
- path = require('path'),
|
|
|
17
|
- bodyParser = require('body-parser'),
|
|
|
18
|
- cookieParser = require('cookie-parser'),
|
|
|
19
|
- favicon = require('serve-favicon'),
|
|
|
20
|
- pkg = require('./package.json');
|
15
|
+const express = require('express');
|
|
|
16
|
+const path = require('path');
|
|
|
17
|
+const bodyParser = require('body-parser');
|
|
|
18
|
+const cookieParser = require('cookie-parser');
|
|
|
19
|
+const favicon = require('serve-favicon');
|
|
|
20
|
+const session = require('express-session');
|
|
|
21
|
+const memcached = require('connect-memcached');
|
|
|
22
|
+const pkg = require('./package.json');
|
21
|
|
23
|
|
22
|
-require('express-handlebars');
|
24
|
+const app = express();
|
|
|
25
|
+const MemcachedStore = memcached(session);
|
23
|
|
26
|
|
24
|
|
27
|
|
25
|
-let app = express();
|
|
|
26
|
-
|
|
|
27
|
// 向模板注入变量
|
28
|
// 向模板注入变量
|
28
|
app.locals.devEnv = app.get('env') === 'development';
|
29
|
app.locals.devEnv = app.get('env') === 'development';
|
29
|
app.locals.version = pkg.version;
|
30
|
app.locals.version = pkg.version;
|
30
|
|
31
|
|
|
|
32
|
+// 指定libray目录
|
|
|
33
|
+global.library = path.resolve('./library');
|
|
|
34
|
+
|
31
|
app.set('view engine', '.hbs');
|
35
|
app.set('view engine', '.hbs');
|
32
|
|
36
|
|
33
|
app.use(favicon(path.join(__dirname, '/public/favicon.ico')));
|
37
|
app.use(favicon(path.join(__dirname, '/public/favicon.ico')));
|
|
@@ -35,11 +39,22 @@ app.use(express.static(path.join(__dirname, 'public'))); |
|
@@ -35,11 +39,22 @@ app.use(express.static(path.join(__dirname, 'public'))); |
35
|
app.use(bodyParser.json());
|
39
|
app.use(bodyParser.json());
|
36
|
app.use(bodyParser.urlencoded({extended: false}));
|
40
|
app.use(bodyParser.urlencoded({extended: false}));
|
37
|
app.use(cookieParser());
|
41
|
app.use(cookieParser());
|
|
|
42
|
+app.use(session({
|
|
|
43
|
+ secret: '3e5fec7deca0b8305cefe2ad9d90ff5e',
|
|
|
44
|
+ name: 'PHPSESSID',
|
|
|
45
|
+ prefix: 'yohobuy',
|
|
|
46
|
+ proxy: true,
|
|
|
47
|
+ resave: true,
|
|
|
48
|
+ saveUninitialized: true,
|
|
|
49
|
+ store: new MemcachedStore({
|
|
|
50
|
+ hosts: config.memcache.session
|
|
|
51
|
+ })
|
|
|
52
|
+}));
|
38
|
|
53
|
|
39
|
// dispatcher
|
54
|
// dispatcher
|
40
|
require('./dispatch')(app);
|
55
|
require('./dispatch')(app);
|
41
|
|
56
|
|
42
|
// listener
|
57
|
// listener
|
43
|
-app.listen(6001, function() {
|
58
|
+app.listen(config.port, function() {
|
44
|
console.log('yohobuy start');
|
59
|
console.log('yohobuy start');
|
45
|
}); |
60
|
}); |