Last active
July 2, 2020 12:22
-
-
Save zimplexing/c7c1f15ea3f270de3962fc0ab466d82e to your computer and use it in GitHub Desktop.
追书神器api代理地址
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const request = require('request'); | |
const app = express(); | |
const proxyServer = 'http://api.zhuishushenqi.com'; | |
const chapterServer = 'http://chapterup.zhuishushenqi.com/chapter' | |
//设置跨域访问 | |
app.all('*', function (req, res, next) { | |
res.header("Access-Control-Allow-Credentials", true); | |
res.header("Access-Control-Allow-Origin", "*"); | |
res.header("Access-Control-Allow-Headers", "X-Requested-With, accept, origin, content-type, x-access-token"); | |
res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS"); | |
next(); | |
}); | |
app.get('/getChapter', (req, res, next) => { | |
const url = chapterServer + '/' + req.query.chapterUrl; | |
console.log(url); | |
req.pipe(request(url)).pipe(res); | |
}); | |
app.use('/', (req, res) => { | |
const url = proxyServer + req.url; | |
console.log(url); | |
req.pipe(request(url)).pipe(res); | |
}); | |
app.listen(3000, function () { | |
console.log('proxy server started at: localhsot:3000'); | |
}); |
我试了放在build没有用
我试了放在build没有用
@Joezhangs
1.命令行启动它
node nodeProxy.js
2.将项目中main.js的地址改成nodeProxy.js监听的http://localhost:3000/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
想问下这个问价添加到项目哪里