Showing
6 changed files
with
20 additions
and
15 deletions
@@ -22,7 +22,7 @@ From: [eslint-config-yoho](https://www.npmjs.com/package/eslint-config-yoho) | @@ -22,7 +22,7 @@ From: [eslint-config-yoho](https://www.npmjs.com/package/eslint-config-yoho) | ||
22 | # 项目启动方法 | 22 | # 项目启动方法 |
23 | 23 | ||
24 | - 拉取代码 | 24 | - 拉取代码 |
25 | -- 安装全局包:`eslint`,`eslint-config-yoho`,`yo`,`generators-yohos` | 25 | +- 安装全局包:`npm i -g eslint eslint-config-yoho yo generator-yohos nodemon` |
26 | - 安装本地依赖 | 26 | - 安装本地依赖 |
27 | - 启动 Web Server 服务进程:当前目录下运行`npm start` | 27 | - 启动 Web Server 服务进程:当前目录下运行`npm start` |
28 | - 进入模块的静态资源目录,运行`gulp` | 28 | - 进入模块的静态资源目录,运行`gulp` |
@@ -15,19 +15,20 @@ var logger = require('morgan'), | @@ -15,19 +15,20 @@ var logger = require('morgan'), | ||
15 | session = require('express-session'), | 15 | session = require('express-session'), |
16 | connectRedis = require('connect-redis'); | 16 | connectRedis = require('connect-redis'); |
17 | 17 | ||
18 | -var config = require('./config'); | ||
19 | - | ||
20 | var app = express(), | 18 | var app = express(), |
21 | RedisStore = connectRedis(session); | 19 | RedisStore = connectRedis(session); |
22 | 20 | ||
23 | -// 向模板注入变量 | ||
24 | -app.locals.devEnv = app.get('env') === 'development'; | 21 | +var config = require('./config'); |
25 | 22 | ||
26 | // 根据不同环境获取不同配置 | 23 | // 根据不同环境获取不同配置 |
27 | -if (app.locals.devEnv) { | 24 | +if (app.get('env') === 'development') { |
28 | config = Object.assign(config, require('./config/config.dev')); | 25 | config = Object.assign(config, require('./config/config.dev')); |
29 | } | 26 | } |
30 | 27 | ||
28 | +// 向模板注入变量 | ||
29 | +app.locals.devEnv = app.get('env') === 'development'; | ||
30 | +app.locals.assetsUrl = config.assetsUrl; | ||
31 | + | ||
31 | app.set('trust proxy', ['loopback', 'linklocal', 'uniquelocal']); | 32 | app.set('trust proxy', ['loopback', 'linklocal', 'uniquelocal']); |
32 | app.set('views', path.join(__dirname, 'views/action')); | 33 | app.set('views', path.join(__dirname, 'views/action')); |
33 | app.set('view engine', 'hbs'); | 34 | app.set('view engine', 'hbs'); |
1 | module.exports = { | 1 | module.exports = { |
2 | + assetsUrl: '//localhost:3000', | ||
2 | sessionRedis: { | 3 | sessionRedis: { |
3 | host: '127.0.0.1', | 4 | host: '127.0.0.1', |
4 | port: 6379, | 5 | port: 6379, |
5 | - prefix: 'activity-node-session:', | 6 | + prefix: 'activity-session-dev:', |
6 | ttl: 3600 // session 默认有效期 | 7 | ttl: 3600 // session 默认有效期 |
7 | }, | 8 | }, |
8 | - sessionSecret: '111' | 9 | + sessionSecret: 'devsession' |
9 | }; | 10 | }; |
1 | module.exports = { | 1 | module.exports = { |
2 | + siteUrl: 'http://www.yohobuy.com', | ||
3 | + assetsUrl: '//cdn.yoho.cn/huodong-node', | ||
2 | sessionRedis: { | 4 | sessionRedis: { |
3 | host: '127.0.0.1', | 5 | host: '127.0.0.1', |
4 | port: 6379, | 6 | port: 6379, |
5 | - prefix: 'activity-node-session:', | 7 | + prefix: 'activity-session:', |
6 | ttl: 3600 // session 默认有效期 | 8 | ttl: 3600 // session 默认有效期 |
7 | }, | 9 | }, |
8 | - sessionSecret: '111' | 10 | + sessionSecret: '0c565c3085bcf9c7ecdb84f57dfc74fb' |
9 | }; | 11 | }; |
@@ -4,6 +4,7 @@ | @@ -4,6 +4,7 @@ | ||
4 | "private": true, | 4 | "private": true, |
5 | "scripts": { | 5 | "scripts": { |
6 | "start": "node ./bin/www", | 6 | "start": "node ./bin/www", |
7 | + "dev": "nodemon -e js -i public/ ./bin/www", | ||
7 | "lint": "eslint -c .eslintrc --fix --cache .", | 8 | "lint": "eslint -c .eslintrc --fix --cache .", |
8 | "validate": "npm ls" | 9 | "validate": "npm ls" |
9 | }, | 10 | }, |
@@ -15,18 +15,18 @@ | @@ -15,18 +15,18 @@ | ||
15 | <link rel="dns-prefetch" href="//img12.static.yhbimg.com"> | 15 | <link rel="dns-prefetch" href="//img12.static.yhbimg.com"> |
16 | <link rel="dns-prefetch" href="//img13.static.yhbimg.com"> | 16 | <link rel="dns-prefetch" href="//img13.static.yhbimg.com"> |
17 | {{#if devEnv}} | 17 | {{#if devEnv}} |
18 | - <link rel="stylesheet" href="//localhost:3000/{{module}}/css/index.css"> | 18 | + <link rel="stylesheet" href="{{assetsUrl}}/{{module}}/dist/css/index.css"> |
19 | {{^}} | 19 | {{^}} |
20 | - <link rel="stylesheet" href="//cdn.yoho.cn/{{module}}/{{version}}/index.css"> | 20 | + <link rel="stylesheet" href="{{assetsUrl}}/{{module}}/{{version}}/index.css"> |
21 | {{/if}} | 21 | {{/if}} |
22 | </head> | 22 | </head> |
23 | <body> | 23 | <body> |
24 | {{{body}}} | 24 | {{{body}}} |
25 | {{#if devEnv}} | 25 | {{#if devEnv}} |
26 | - <script type="text/javascript" src="//localhost:8002/index.js"></script> | 26 | + <script type="text/javascript" src="{{assetsUrl}}/{{module}}/dist/js/index.js"></script> |
27 | {{^}} | 27 | {{^}} |
28 | - <script type="text/javascript" src="//cdn.yoho.cn/{{module}}/{{version}}/lib.js"></script> | ||
29 | - <script type="text/javascript" src="//cdn.yoho.cn/{{module}}/{{version}}/index.js"></script> | 28 | + <script type="text/javascript" src="{{assetsUrl}}/{{module}}/{{version}}/lib.js"></script> |
29 | + <script type="text/javascript" src="{{assetsUrl}}/{{module}}/{{version}}/index.js"></script> | ||
30 | {{/if}} | 30 | {{/if}} |
31 | </body> | 31 | </body> |
32 | </html> | 32 | </html> |
-
Please register or login to post a comment