No response using express proxy route

后端 未结 5 901
执念已碎
执念已碎 2020-12-07 08:55

I\'ve written a small proxy with nodejs, express and htt-proxy. It works well for serving local files but fails when it comes to proxy to external api:

var e         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-07 09:35

    I ended up using http-proxy-middleware.

    The code looks something like this:

    var express = require("express");
    var proxy = require("http-proxy-middleware");
    
    const theProxy = proxy({
      target: "query.yahooapis.com",
      changeOrigin: true,
    });
    
    app.use("/", theProxy);
    app.listen(process.env.PORT || 3002);
    

提交回复
热议问题