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 23f97cc

Browse files
⚡ 改进:本地代理1返回数据格式改为Object
1 parent f03e59a commit 23f97cc

File tree

10 files changed

+36
-74
lines changed

10 files changed

+36
-74
lines changed

‎douban/app.js‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
const Koa = require('koa')
2-
const mount = require('koa-mount')
2+
const router = require('koa-router')()
3+
const request = require('co-request')
34

4-
const router = require('./router')
5+
const URI = 'https://api.douban.com/v2/movie'
6+
router.prefix('/douban')
7+
router.get('/:type', async ctx => {
8+
let result
9+
try {
10+
let url = ctx.url.replace(/\/douban(\w*)/, URI + '1ドル')
11+
console.log(':::', url, ':::')
12+
result = await request({uri: url, method: ctx.method}) // 返回的是字符串
13+
} catch (error) {
14+
throw new Error(error)
15+
} finally {
16+
ctx.body = JSON.parse(result.body)
17+
}
18+
})
519

620
const app = new Koa()
7-
8-
app.use(mount('/', router))
21+
app.use(router.routes())
922

1023
app.listen(3001, () => {
1124
console.log(`Server started on 3001`)

‎douban/router.js‎

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

‎package-lock.json‎

Lines changed: 11 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"start": "node build/dev-server.js",
1010
"build": "node build/build.js",
1111
"lint": "eslint --ext .js,.vue src",
12-
"server": "node douban/app.js"
12+
"server": "node douban/app.js",
13+
"proxy": "node douban/proxy.js"
1314
},
1415
"dependencies": {
1516
"flyio": "^0.4.5",
@@ -44,10 +45,10 @@
4445
"friendly-errors-webpack-plugin": "^1.1.3",
4546
"glob": "^7.1.2",
4647
"html-webpack-plugin": "^2.28.0",
47-
"http-proxy-middleware": "^0.17.3",
48+
"http-proxy-middleware": "^0.17.4",
4849
"koa": "^2.5.0",
49-
"koa-mount": "^3.0.0",
5050
"koa-router": "^7.4.0",
51+
"koa2-connect": "^1.0.2",
5152
"mpvue-loader": "^1.0.8",
5253
"mpvue-template-compiler": "^1.0.6",
5354
"mpvue-webpack-target": "^1.0.0",

‎src/pages/board/index.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default {
6464
let boards = await Promise.all(tasks)
6565
let data
6666
this.boards = this.boards.map((board, i) => {
67-
data = JSON.parse(boards[i])
67+
data = boards[i]
6868
board.title = data.title
6969
board.movies = data.subjects
7070
return board

‎src/pages/list/index.vue‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export default {
2929
if (!this.hasMore) return
3030
3131
let data = await getBoardData({ board: this.type, page: this.page++ })
32-
data = JSON.parse(data)
3332
3433
if (data.subjects.length) {
3534
this.movies.push.apply(this.movies, data.subjects)

‎src/pages/search/index.vue‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export default {
3131
if (!this.hasMore) return
3232
3333
let data = await getBoardData({ board: 'search', page: this.page++, search: this.q })
34-
data = JSON.parse(data)
3534
3635
if (data.subjects.length) {
3736
this.movies.push.apply(this.movies, data.subjects)

‎src/pages/splash/index.vue‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export default {
5151
return
5252
}
5353
let data = await getBoardData({board: 'coming_soon', page: 1, count: 3})
54-
data = JSON.parse(data)
5554
this.movies = data.subjects
5655
await setStorage('last_splash_data', {
5756
movies: data.subjects,

‎src/store/modules/item.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const state = {
99
const mutations = {
1010
[MOVIE_DETAIL]: (state, { data, match }) => {
1111
if (!match) {
12-
data = JSON.parse(data)
1312
state.movieDetails.unshift(data)
1413
}
1514
state.movie = data

‎src/utils/request.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import Fly from 'flyio'
44
const request = new Fly()
55

66
request.config.timeout = 10 * 1000
7-
// request.config.baseURL = 'https://movie.douban.gusaifei.com/'
8-
request.config.baseURL = 'http://localhost:3001/douban'
7+
// request.config.baseURL = 'https://movie.douban.gusaifei.com/v2/movie' // nginx 代理(100次/小时)
8+
request.config.baseURL = 'http://localhost:3001/douban' // 本地代理1(100次/小时)
9+
// request.config.baseURL = 'http://localhost:3002' // 本地代理2(100次/小时)
910

1011
request.interceptors.request.use((request) => {
1112
wx.showLoading({ title: '拼命加载中...' })

0 commit comments

Comments
(0)

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