I share the config that I used updating Proxy with Bypass settings (before Angular 18) to Proxy using http-proxy-middleware (since Angular 18 https://angular.dev/tools/cli/serve#proxying-to-a-backend-server)
angular.json config
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"totoTestProfile": {
"buildTarget": "your-application:build",
"proxyConfig": "proxy/proxy.conf.js"
},
Before Upgrade (Angular < 18)
proxy.conf.js config :
const PROXY_CONFIG = {
context: [
"/api",
"/oauth2",
"/login/oauth2",
"/exploitation"
],
"target": "http://localhost:8083/",
"secure": false,
"bypass": function (req, res, proxyOptions) {
req.headers["webpass-remote-user"] = "TOTO_USER";
}
}
module.exports = PROXY_CONFIG;
After Upgrade (Angular 18)
proxy.conf.js config :
const PROXY_CONFIG = [
{
context: [
"/api",
"/oauth2",
"/login/oauth2",
"/exploitation"
],
"target": "http://localhost:8083/",
"secure": false,
onProxyReq: (proxyReq) => {
proxyReq.setHeader('webpass-remote-user','TOTO_USER');
},
},
];
module.exports = PROXY_CONFIG;
and you need to add http-proxy-middleware to devDependencies in package.json
npm install --save-dev http-proxy-middleware
launch your app with
ng serve --configuration=totoTestProfile