How to solve Error while proxying to API in localhost

本秂侑毒 提交于 2020-03-25 13:44:43

问题


i have setup the following proxies:

const app = require('express')();
const  proxy = require('http-proxy-middleware');


app.use('/api', proxy({ target: 'https://swapi-graphql.netlify.com/.netlify/functions/index', changeOrigin: true})); 
app.use('/image', proxy({ target: 'localhost:8000' , changeOrigin: true})); 


app.listen(8080);

The /api route proxies normally but the /image proxy returns the following error :

[HPM] Error occurred while trying to proxy request /image from localhost:8080 to localhost:8000 (ENOTFOUND) (https://nodejs.org/api/errors.html#errors_common_system_errors)

The issue is not in my image api because when i post directly to the /image route, the issue doesnt happen. Only when i do it via port 8080.

What I tried:

Changing the port -> didnt work

来源:https://stackoverflow.com/questions/60227022/how-to-solve-error-while-proxying-to-api-in-localhost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!