Skip to content

Commit 3de4d5a

Browse files
hong-boy袁洪波
authored andcommitted
更新目录结构:新增src/
更新task:pakcage任务
1 parent 2956162 commit 3de4d5a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+350
-165
lines changed

tomato/README.md

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,51 @@
11
## koa2 + Vue2.0
22

3-
### 目录说明
4-
---
5-
├─app
6-
│ ├─controller
7-
│ ├─routes
8-
│ └─util
9-
├─bin
10-
├─config
11-
│ ├─build
12-
│ └─env
13-
├─dist
14-
├─logs
15-
├─test
16-
└─views
3+
* 环境依赖
4+
* 开始
5+
* 目录结构说明
6+
* 目标
7+
8+
### 环境依赖
9+
* Nodejs 7或者babel编译
1710

11+
### 开始
12+
* 安装依赖:```npm install```
13+
* 启动:```npm run start```
14+
* webpack实时编译:```npm run watch```
15+
* 生产环境打包:```npm run pkg```
16+
* 单元测试:```npm test```
17+
* 代码覆盖率:```npm run test:cover```
18+
19+
### 目录结构说明
20+
```
21+
---
22+
├─bin
23+
├─config
24+
│ ├─build
25+
│ ├─env
26+
│ ├─passport
27+
│ ├─privs
28+
│ └─session
29+
├─coverage
30+
├─dist
31+
├─logs
32+
├─src
33+
│ ├─app
34+
│ │ ├─bean
35+
│ │ ├─controller
36+
│ │ ├─route
37+
│ │ └─util
38+
│ └─views
39+
│ ├─assets
40+
│ │ ├─image
41+
│ │ └─less
42+
│ ├─components
43+
│ │ ├─common
44+
│ ├─routes
45+
│ └─utils
46+
└─test
1847
---
48+
```
1949

2050
### 目标
2151
1. Vue2作为视图层,Koa2作为控制层

tomato/bin/startup

Lines changed: 0 additions & 88 deletions
This file was deleted.

tomato/bin/startup.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var app = require('../src/app');
8+
var http = require('http');
9+
var conf = require('../config/env.js');
10+
var logger = require('./util/Logger').logger('startup.js');
11+
12+
/**
13+
* Get port from environment and store in Express.
14+
*/
15+
16+
var port = normalizePort(conf.port);
17+
// app.set('port', port);
18+
19+
/**
20+
* Create HTTP server.
21+
*/
22+
23+
var server = http.createServer(app.callback());
24+
25+
/**
26+
* Listen on provided port, on all network interfaces.
27+
*/
28+
29+
server.listen(port);
30+
server.on('error', onError);
31+
server.on('listening', onListening);
32+
33+
/**
34+
* Normalize a port into a number, string, or false.
35+
*/
36+
37+
function normalizePort(val) {
38+
var port = parseInt(val, 10);
39+
40+
if (isNaN(port)) {
41+
// named pipe
42+
return val;
43+
}
44+
45+
if (port >= 0) {
46+
// port number
47+
return port;
48+
}
49+
50+
return false;
51+
}
52+
53+
/**
54+
* Event listener for HTTP server "error" event.
55+
*/
56+
57+
function onError(error) {
58+
if (error.syscall !== 'listen') {
59+
throw error;
60+
}
61+
62+
var bind = typeof port === 'string'
63+
? 'Pipe ' + port
64+
: 'Port ' + port;
65+
66+
// handle specific listen errors with friendly messages
67+
switch (error.code) {
68+
case 'EACCES':
69+
console.error(bind + ' requires elevated privileges');
70+
process.exit(1);
71+
break;
72+
case 'EADDRINUSE':
73+
console.error(bind + ' is already in use');
74+
process.exit(1);
75+
break;
76+
default:
77+
throw error;
78+
}
79+
}
80+
81+
/**
82+
* Event listener for HTTP server "listening" event.
83+
*/
84+
85+
function onListening() {
86+
let protocol = 'http';
87+
logger.info(`Server is ready! Visit on ${protocol}://localhost:${port}${conf.project}`);
88+
}

tomato/config/build/webpack.base.conf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const rootdir = app.rootdir;
1010
const conf = {
1111
entry: {
1212
babelMain: 'babel-polyfill',
13-
main: path.join(rootdir, 'views', 'main.js')
13+
main: path.join(rootdir, 'src/views', 'main.js')
1414
},
1515
output: {
1616
path: path.join(rootdir, dist),
@@ -41,7 +41,7 @@ const conf = {
4141
inject: true,
4242
project: app.project,
4343
filename: 'index.html',
44-
template: path.resolve(rootdir, 'views', 'index.html')
44+
template: path.resolve(rootdir, 'src/views', 'index.html')
4545
}),
4646
new webpack.optimize.CommonsChunkPlugin({
4747
name: "common",

tomato/config/build/webpack.prod.conf.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ module.exports = merge(base, {
1818
warnings: false
1919
}
2020
}),
21+
new webpack.optimize.CommonsChunkPlugin({
22+
name: "common",
23+
filename: "[name].bundle.[hash].js"
24+
}),
2125
new webpack.DefinePlugin({
2226
"process.env": {
2327
NODE_ENV: JSON.stringify("production")
2428
}
2529
})
2630
]
27-
});
31+
});

tomato/config/env.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ if (process && process.env && process.env.NODE_ENV) {
88
} else {
99
console.info('No NODE_ENV specified! It will use [dev.conf.js] as default...');
1010
}
11+
1112
configure = isProd ? require('./env/prod.conf') : require('./env/dev.conf');
1213

13-
module.exports = configure;
14+
module.exports = configure;

tomato/config/env/base.conf.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,37 @@ let path = require('path');
33
let rootdir = path.resolve(__dirname, '../../'); // 工程根路径
44
const project = '/koa2';
55
const conf = {
6-
project: project,
7-
port: 3000,
8-
rootdir: rootdir,
9-
debug: false, // true-开发模式 false-生产环境
10-
env: process.env.NODE_ENV || 'develpoment',
11-
dist: 'dist', // webpack打包输出路径
12-
defaultPage: 'index.html',
13-
allowedFileExtension: ['.js', '.css', '.html', '.ttf', '.woff'], // 定义允许下载的文件类型
14-
log4js: {
15-
level: 'debug',
16-
output: path.join(rootdir, 'logs/app.log')
17-
},
18-
webservice: {
19-
url: 'http://localhost:8001',
20-
ver: '/web',
21-
connectTimeout: false,
22-
requestTimeout: false
23-
},
24-
session: {
25-
key: 'sid',
26-
store: undefined, // Session第三方存储
27-
maxAge: 3600 * 1000, // 60mins
28-
httpOnly: true,
29-
path: project
30-
},
31-
redis: { // 通常一个项目只需配置一台redis服务器即可
32-
host: '127.0.0.1',
33-
port: 6379,
34-
db: 15
35-
},
36-
store: null // 定义将项目中的常量存储于何处。null:NodeJS内存(默认) redis:Redis服务器
6+
project: project,
7+
port: 3000,
8+
rootdir: rootdir,
9+
debug: false, // true-开发模式 false-生产环境
10+
env: process.env.NODE_ENV || 'develpoment',
11+
dist: 'dist', // webpack打包输出路径
12+
defaultPage: 'index.html',
13+
allowedFileExtension: ['.js', '.css', '.html', '.ttf', '.woff'], // 定义允许下载的文件类型
14+
log4js: {
15+
level: 'debug',
16+
output: path.join(rootdir, 'logs/app.log')
17+
},
18+
webservice: {
19+
url: 'http://localhost:8001',
20+
ver: '/web',
21+
connectTimeout: false,
22+
requestTimeout: false
23+
},
24+
session: {
25+
key: 'sid',
26+
store: undefined, // Session第三方存储
27+
maxAge: 3600 * 1000, // 60mins
28+
httpOnly: true,
29+
path: project
30+
},
31+
redis: { // 通常一个项目只需配置一台redis服务器即可
32+
host: '127.0.0.1',
33+
port: 6379,
34+
db: 15
35+
},
36+
store: null // 定义将项目中的常量存储于何处。null:NodeJS内存(默认) redis:Redis服务器
3737
};
3838

3939
module.exports = conf;

tomato/config/env/prod.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = deepMerge({
1313
},
1414
session: {
1515
key: 'prdsid',
16-
store: new (require('../session/redis.store.js'))()
16+
store: require('../session/redis.store.js') // 传入SessionStore类
1717
},
1818
store: 'redis'
1919
}, base);

tomato/config/passport/strgy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const passport = require('koa-passport');
33
const lodash = require('lodash/object');
44
const conf = require('../privs.js');
5-
const StoreUtil = require('../../app/util/Store');
5+
const StoreUtil = require('.././util/Store');
66
const PREFIX_4_ROLE = 'koa:role';
77
const MAXAGE_4_ROLE = require('../env.js').session.maxAge;
88

0 commit comments

Comments
 (0)