search

Home  >  Q&A  >  body text

node.js - http-proxy-middleware cannot proxy

Like the title
I use ajax to request cross-domain data on the page
This is the address I want to proxy, the local service is locahost:1983
But when the request is not received, it always goes to error. What's going on?

var apiProxy = proxyMiddleware('/v2', { target: 'https://api.douban.com',changeOrigin: true });
app.use('/v2/*', apiProxy);
$.ajax({
    type: "get",
    url: "http://localhost:1983/v2/book/search?q=javascript&alt=json&callback=fn1&start=" + (opage++) + "&count=20",
    success: function(data) {
        var odata = data.books;
        var ohtml = "";
        for (var i = 0; i < odata.length; i++) {
            ohtml += "<li><img src=" + odata[i]["images"]["small"] + "><p>" + odata[i]["title"] + "</p></li>";
        }
        $("#special").append(ohtml);
    },
    error: function() {
        alert("出错");
    }
});

Error reported by the control console

Open the link in the browser and display

怪我咯怪我咯2839 days ago686

reply all(1)I'll reply

  • 阿神

    阿神2017-05-16 13:33:25

    However, you are still requesting api.douban.com across domains. Of course ajax still goes into error
    I have come back to this problem several times: /q/10...

    reply
    0
  • Cancelreply