Skip to content

Instantly share code, notes, and snippets.

@dunnza
Last active November 7, 2022 07:54
Show Gist options
  • Save dunnza/67c7f1705daba5a1bb5f750d5f5766b1 to your computer and use it in GitHub Desktop.
Save dunnza/67c7f1705daba5a1bb5f750d5f5766b1 to your computer and use it in GitHub Desktop.
How to proxy api requests with NTLM authentication in a create-react-app project
const http = require("http");
const proxy = require("http-proxy-middleware");
module.exports = function(app) {
app.use(
"/api",
proxy({
agent: new http.Agent({ keepAlive: true }),
target: "http://example.com/",
onProxyRes(proxyRes) {
const header = "www-authenticate";
proxyRes.headers[header] =
proxyRes.headers[header] && proxyRes.headers[header].split(",");
}
})
);
};
@nullberri
Copy link

Still fails most of the time. I usually have to make an API call in a new tab (ie http://testEnv/api/bootstrap) to the real site to get any connections to work via the local proxy on any consistent basis. otherwise it just get hung on sending basic auth info over and over again.

@dunnza
Copy link
Author

dunnza commented Feb 14, 2019

@nullberri what is your setup like? I'm running an ASP.NET Core WebAPI application through Visual Studio (IIS Express). I haven't encountered any problems yet ...

@TeonWasTaken
Copy link

@dunnza - thanks very much for sharing this. Worked perfectly for me and got me out of a bind.

@dunnza
Copy link
Author

dunnza commented Jun 6, 2019

@TeonWasTaken I'm glad it helped you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment