-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
52 lines (39 loc) · 1.31 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const Koa = require('koa');
const router = require('koa-router')();
const koaBody = require('koa-body')();
const app = new Koa();
// 首页 —— 轮播图数据
const homeCateGory = require('./home/homeCategory');
router.get('/api/homeCategory', (ctx, next) => {
ctx.body = homeCateGory;
});
// 首页 —— 广告(超值特惠)
const homeAdData = require('./home/ad');
router.get('/api/homead', (ctx, next) => {
ctx.body = homeAdData;
});
// 首页 —— 推荐雷彪(猜你喜欢)
const homeListData = require('./home/list');
router.get('/api/homelist/:city/:page', (ctx, next) => {
// 参数
const params = ctx.params;
const paramsCity = params.city;
const paramsPage = params.page;
console.log(`当前城市:${paramsCity}`);
console.log(`当前页数:${paramsPage}`);
ctx.body = homeListData;
});
// 选择城市 - 热门城市
const hotCityListData = require('./home/hotCityList');
router.get('/api/hotCityList', ctx => {
ctx.body = hotCityListData;
});
// router.post('/api/post', koaBody, (ctx, next) => {
// console.log(ctx.request.body);
// ctx.body = JSON.stringify(ctx.request.body)
// });
app.use(router.routes())
.use(router.allowedMethods());
app.listen(3000, () => {
console.log('mock服务器已启动: http:https://localhost:3000/');
});