Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ff7ada6

Browse files
committed
📝 文档:增加本地代理
1 parent c4f824e commit ff7ada6

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

‎README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66

77
![mpvue-douban](mpvue-douban.gif)
88

9+
## 本地代理
10+
11+
进入到 `douban` 目录,运行 `app.js`,或者直接运行 npm scripts:
12+
13+
```bash
14+
npm run server
15+
```
16+
917
## Build Setup
1018

1119
``` bash

‎douban/app.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ const app = new Koa()
88
app.use(mount('/', router))
99

1010
app.listen(3001, () => {
11-
console.log(`Server started on 3000`)
11+
console.log(`Server started on 3001`)
1212
})

‎douban/router.js‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,29 @@ const URI = 'https://api.douban.com/v2/movie'
77
router.prefix('/douban')
88

99
router.get('/:type', async ctx => {
10-
let url = ctx.url.replace(/\/douban(\w*)/, URI + '1ドル')
11-
console.log(':::', url, ':::')
12-
let result = await request({uri: url, method: ctx.method})
13-
ctx.body = result.body
10+
let result
11+
try {
12+
let url = ctx.url.replace(/\/douban(\w*)/, URI + '1ドル')
13+
console.log(':::', url, ':::')
14+
result = await request({uri: url, method: ctx.method})
15+
} catch (error) {
16+
throw new Error(error)
17+
} finally {
18+
ctx.body = result.body
19+
}
1420
})
1521

1622
router.get('/:type/:id', async ctx => {
17-
let url = ctx.url.replace(/\/douban(\w*)/, URI + '1ドル')
18-
console.log(':::', url, ':::')
19-
let result = await request({uri: url, method: this.method})
20-
ctx.body = result.body
23+
let result
24+
try {
25+
let url = ctx.url.replace(/\/douban(\w*)/, URI + '1ドル')
26+
console.log(':::', url, ':::')
27+
result = await request({uri: url, method: ctx.method})
28+
} catch (error) {
29+
throw new Error(error)
30+
} finally {
31+
ctx.body = result.body
32+
}
2133
})
2234

2335
module.exports = router.routes()

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"dev": "node build/dev-server.js",
99
"start": "node build/dev-server.js",
1010
"build": "node build/build.js",
11-
"lint": "eslint --ext .js,.vue src"
11+
"lint": "eslint --ext .js,.vue src",
12+
"server": "node douban/app.js"
1213
},
1314
"dependencies": {
1415
"flyio": "^0.4.5",

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /