Comments (3)
嗯...我没弄过请求代理。
记得在webpack里可以配置proxy来着,不知道行不行
我回头试试
from react-luo.
试了一下,可以成功代理:
server.js中加入以下代码:
const proxy = require("http-proxy-middleware");
const options = {
target: 'https://api.douban.com',
changeOrigin: true,
ws: false,
pathRewrite: {
'^/api/' : '/'
},
};
const testProxy = proxy(options);
app.use('/api', testProxy);
然后请求以下地址:
axios({
url: '/api/v2/music/search?q=周杰伦',
method: "get",
headers: {
"Content-Type": "application/json;charset=utf-8"
},
withCredentials: true,
});
可以成功返回数据
from react-luo.
谢谢,我自己已经解决了,我设置代理的那块代码位置放的不对,要放在express处理路由前
from react-luo.
Related Issues (20)
- 这个报错怎么回事:Warning: Hash history cannot PUSH the same path; a new entry will not be added to the history stack HOT 6
- css 样式里面的本地图片路径怎么打包到build里面 HOT 1
- css打包后怎么class名称后都加了这个后缀_7Z3_vq74 而html div 没有加后缀 导致样式名称不对 HOT 1
- 内存溢出 HOT 5
- 服务器记录路由跳转 HOT 1
- 无法引入第三方样式 HOT 2
- ajax请求如何记录 HOT 1
- 引用相对路径图片 报错 HOT 4
- 切换成url 模式 模式报错 HOT 5
- 支持ssr HOT 2
- 添加对scss的支持 HOT 3
- mac上无法跑成功,node版本为8.11.0,同版本node可以在windows上跑通 HOT 11
- 有很多路由的时候,有什么简便的写法么? HOT 3
- 不做公共代码抽取么? HOT 1
- webpack5 HOT 3
- webpack 的loader配置应该不支持 antd 吧 HOT 3
- 开发ts版本 HOT 1
- 整个storybook HOT 1
- help! HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-luo.