Skip to content

Instantly share code, notes, and snippets.

@zimplexing
Last active July 2, 2020 12:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zimplexing/c7c1f15ea3f270de3962fc0ab466d82e to your computer and use it in GitHub Desktop.
Save zimplexing/c7c1f15ea3f270de3962fc0ab466d82e to your computer and use it in GitHub Desktop.
追书神器api代理地址
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');
});
@Joezhangs
Copy link

想问下这个问价添加到项目哪里

@Joezhangs
Copy link

我试了放在build没有用

@ZhoDi
Copy link

ZhoDi commented Nov 25, 2019

我试了放在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