Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy server target uses port of proxy instead of target port specified #1672

Open
mdmc4ll1st3r opened this issue Jun 29, 2024 · 1 comment

Comments

@mdmc4ll1st3r
Copy link

Greetings!

I have created what should be a simple proxy server on my system:

var httpProxy = require('http-proxy');

httpProxy.createProxyServer(
  {
    secure: false,
    target: 'https://www.google.com:443'
  }
).listen(3000);

When attempting to access this proxy server via web browser, I'm noticing in the network traffic that the target port number (443) is being ignored and the target request ends up using the same port number as that used by the proxy server (3000). In other words, the request ends up going to https://www.google.com:3000 instead of https://www.google.com:443.

The version of http-proxy specified in my package.json is ^1.18.1.

I am deploying my application using CLI tool forever.

Is there an obvious configuration that I am missing to get my target port to be respected?

@mdmc4ll1st3r
Copy link
Author

Greetings future traveler!

I was able to use a different project (http-proxy-middleware) to get the desired behavior of setting up a proxy server using different ports for the proxy and target. Proxy server code below:

const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');

const app = express();

app.use(
  '/api',
  createProxyMiddleware({
    changeOrigin: true,
    pathRewrite: {'^/api' : ''},
    secure: false,
    target: 'https://www.google.com'
  }),
);

app.listen(3000);

Note that I have included a path-rewrite configuration to this code; this was needed for my eventual use case as the changeOrigin setting currently adds a trailing slash to the target path (so for the example it would target https://www.google.com/ instead of https://www.google.com which may be a problem for certain REST patterns).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant