Skip to content

Commit eb8ae54

Browse files
author
wangjingbo
committed
new
0 parents  commit eb8ae54

File tree

13 files changed

+504
-0
lines changed

13 files changed

+504
-0
lines changed

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Logs
2+
logs
3+
*.log
4+
.vscode
5+
# Runtime data
6+
pids
7+
*.pid
8+
*.seed
9+
10+
# Directory for instrumented libs generated by jscoverage/JSCover
11+
lib-cov
12+
13+
# Coverage directory used by tools like istanbul
14+
coverage
15+
16+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17+
.grunt
18+
19+
# node-waf configuration
20+
.lock-wscript
21+
22+
# Compiled binary addons (http://nodejs.org/api/addons.html)
23+
build/Release
24+
25+
# Dependency directory
26+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
27+
node_modules

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#backend-pratt API
2+
3+
###1. 运行环境
4+
* nodejs v6.9.1
5+
* 运行方式
6+
7+
> 如果没有数据模型,初始化数据模型
8+
9+
```javascript
10+
npm run sync
11+
```
12+
13+
> 运行系统 **端口可自定义配置 文件config port: 3001**
14+
15+
```javascript
16+
npm start
17+
```
18+
19+
### 2. 数据库模型
20+
21+
[数据库设计](doc/model.md)
22+
23+
### 3. API
24+
25+
[API规范](doc/api.md)

app.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
let Application = require('koa');
3+
let compress = require('koa-compress');
4+
let bodyParser = require('koa-bodyparser');
5+
let _router = require('koa-router')();
6+
let logger = require('koa-logger');
7+
let cors = require('koa-cors');
8+
9+
let config = require('./config/config.js');
10+
let routes = require('./routes.js');
11+
12+
let app = Application();
13+
// 日志记录
14+
app.use(logger());
15+
16+
// 跨域
17+
app.use(cors());
18+
19+
// body 解析
20+
app.use(bodyParser());
21+
22+
routes.init(_router);
23+
24+
app.use(_router.routes());
25+
26+
27+
// Compress
28+
app.use(compress());
29+
30+
app.listen(config.port || 3000);
31+
console.log('listening on port %s', config.port || 3000);
32+
module.exports = app;

config/config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
let config = {
4+
// 端口号配置
5+
port: 3000,
6+
// 数据库配置
7+
db: {
8+
host: '127.0.0.1',
9+
dialect: 'mysql',
10+
port: '3306',
11+
database: 'test',
12+
username: 'root',
13+
password: '123456'
14+
},
15+
}
16+
17+
//当NODE_ENV环境变量值为development时
18+
module.exports = config

doc/api.md

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
### backend API设计
2+
---
3+
4+
### 1. GET规范
5+
6+
* 请求规范
7+
8+
```javascript
9+
req = {
10+
current: 1,
11+
pageSize: 10,
12+
isPage: 1
13+
children: 0
14+
}
15+
```
16+
* 响应规范
17+
18+
```javascript
19+
resp = {
20+
code: 0,
21+
message: string,
22+
content: {
23+
total: 1,
24+
current: 1,
25+
pageSize: 10,
26+
data: [] || {}
27+
}
28+
}
29+
```
30+
31+
### 2. POST规范
32+
* 请求规范
33+
34+
```
35+
body = JSON.stringify()
36+
37+
```
38+
* 响应规范
39+
40+
```javascript
41+
resp = {
42+
code,
43+
message: 'ok',
44+
content: number
45+
}
46+
47+
```
48+
49+
### 3. PUT规范
50+
* 请求规范
51+
52+
```
53+
ulr = url/:id
54+
body = JSON.stringify()
55+
56+
```
57+
* 响应规范
58+
59+
```javascript
60+
resp = {
61+
code,
62+
message: 'ok'
63+
}
64+
```
65+
66+
### 4.DELETE规范
67+
68+
* 请求规范
69+
70+
```
71+
url = url/:id
72+
```
73+
74+
* 响应规范
75+
76+
```javascript
77+
resp = {
78+
code,
79+
message: 'ok'
80+
}
81+
```
82+
83+
### 5. 相应状态码
84+
```
85+
code 解析码
86+
87+
{
88+
code: 0, //正常
89+
code: 1, //API 异常
90+
code: 2, //参数错误
91+
}
92+
```
93+
94+
###6. API 请求路径
95+
96+
* navgation 导航
97+
98+
```javascript
99+
// 获取所有
100+
{
101+
method: GET,
102+
endpoint: '/navgations'
103+
response: {}
104+
}
105+
106+
// 获取单个
107+
{
108+
method: GET,
109+
endpoint: '/navgation/:id'
110+
response: {}
111+
}
112+
113+
// 更新数据
114+
{
115+
method: PUT,
116+
endpoint: '/navgation/:id'
117+
response: {}
118+
}
119+
```
120+
121+
* classify 分类
122+
123+
```javascript
124+
// 获取所有
125+
{
126+
method: GET,
127+
endpoint: '/classifys'
128+
response: {}
129+
}
130+
131+
// 获取单个
132+
{
133+
method: GET,
134+
endpoint: '/classify/:id'
135+
response: {}
136+
}
137+
// 插入数据
138+
{
139+
method: POST,
140+
endpoint: '/classify'
141+
response: {}
142+
}
143+
144+
// 更新某个
145+
{
146+
method: PUT,
147+
endpoint: '/classify/:id'
148+
response: {}
149+
}
150+
// 删除数据
151+
{
152+
method: DELETE,
153+
endpoint: '/classify/:id'
154+
response: {}
155+
}
156+
```
157+
158+
* aritle 分类
159+
160+
```javascript
161+
// 获取所有
162+
{
163+
method: GET,
164+
endpoint: '/aritles'
165+
response: {}
166+
}
167+
168+
// 获取单个
169+
{
170+
method: GET,
171+
endpoint: '/aritle/:id'
172+
response: {}
173+
}
174+
// 插入数据
175+
{
176+
method: POST,
177+
endpoint: '/aritle'
178+
response: {}
179+
}
180+
181+
// 更新某个
182+
{
183+
method: PUT,
184+
endpoint: '/aritle/:id'
185+
response: {}
186+
}
187+
// 删除数据
188+
{
189+
method: DELETE,
190+
endpoint: '/aritle/:id'
191+
response: {}
192+
}
193+
```
194+
195+
* carousel 轮播
196+
197+
```javascript
198+
// 获取所有
199+
{
200+
method: GET,
201+
endpoint: '/carousels'
202+
response: {}
203+
}
204+
205+
// 获取单个
206+
{
207+
method: GET,
208+
endpoint: '/carousel/:id'
209+
response: {}
210+
}
211+
// 插入数据
212+
{
213+
method: POST,
214+
endpoint: '/carousel'
215+
response: {}
216+
}
217+
218+
// 更新某个
219+
{
220+
method: PUT,
221+
endpoint: '/carousel/:id'
222+
response: {}
223+
}
224+
// 删除数据
225+
{
226+
method: DELETE,
227+
endpoint: '/carousel/:id'
228+
response: {}
229+
}
230+
```
231+
* 上传文件
232+
233+
```javascript
234+
{
235+
method: POST
236+
endpoint: '/upload',
237+
body: {
238+
multipart/form-data
239+
},
240+
response: { "返回文件服务的URL"}
241+
}
242+
```

0 commit comments

Comments
 (0)