Authored by 毕凯

配置优化

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