Http proxy error for target
Asked Answered
G

2

6

I use the following code and it works

          proxy.web(req, res, {
                changeOrigin: true,
                target: 'http://' + hostname + ':' + port,
                ws: true
            });

But when I try the following I got error,why?

proxy.web(req, res, {
                target: {
                    host: 'http://' + hostname,
                    port: port
                },

        });
Greet answered 28/7, 2015 at 10:56 Comment(1)
Please add the error that you get. And also: how do you create the proxy object?Natie
R
4

Because httpProxy.createProxyServer uses url.parse, which will take string as argument you can see the documentatin here https://nodejs.org/docs/latest/api/url.html

you can see the proxy server code here https://github.com/nodejitsu/node-http-proxy/blob/master/lib/http-proxy/index.js

refer line number : 64

Rochette answered 10/8, 2015 at 19:23 Comment(0)
C
3

It's because it only works with string. From https://github.com/nodejitsu/node-http-proxy#options:

httpProxy.createProxyServer supports the following options:

target: url string to be parsed with the url module

Cohleen answered 4/8, 2015 at 6:54 Comment(1)
Can you use client-side SSL with this? Seems you need to add cert, key, and/or ca to the target object (which obviously makes it not a string) for SSL, but that makes the url.parse() fail. I am looking for a way to use both autoRewrite and client-side SSL with http-proxy.Fundus

© 2022 - 2024 — McMap. All rights reserved.