From 7be0678957fe1caaf5298bb2a4cff8652f7dbd2c Mon Sep 17 00:00:00 2001 From: Henri Tremblay Date: Tue, 25 Jun 2024 09:12:40 -0400 Subject: [PATCH] Forward proxy URI from proxy to server to let it pass to oauth2 authentication (close #26521) --- generators/angular/templates/webpack/webpack.custom.js.ejs | 7 +++++++ .../src/main/resources/config/application-dev.yml.ejs | 2 ++ 2 files changed, 9 insertions(+) diff --git a/generators/angular/templates/webpack/webpack.custom.js.ejs b/generators/angular/templates/webpack/webpack.custom.js.ejs index eec477ae8c5f..b89e2a1ba9e3 100644 --- a/generators/angular/templates/webpack/webpack.custom.js.ejs +++ b/generators/angular/templates/webpack/webpack.custom.js.ejs @@ -80,6 +80,13 @@ module.exports = async (config, options, targetOptions) => { proxyOptions: { changeOrigin: false, //pass the Host header to the backend unchanged https://github.com/Browsersync/browser-sync/issues/430 }, + proxyReq: [ + function(proxyReq) { + // URI that will be retrieved by the ForwardedHeaderFilter on the server side + proxyReq.setHeader('X-Forwarded-Host', 'localhost:9000'); + proxyReq.setHeader('X-Forwarded-Proto', 'https'); + } + ] }, socket: { clients: { diff --git a/generators/server/templates/src/main/resources/config/application-dev.yml.ejs b/generators/server/templates/src/main/resources/config/application-dev.yml.ejs index 4b9117fb3621..ef250702ecc3 100644 --- a/generators/server/templates/src/main/resources/config/application-dev.yml.ejs +++ b/generators/server/templates/src/main/resources/config/application-dev.yml.ejs @@ -203,6 +203,8 @@ spring: server: port: <%= serverPort %> + # make sure requests the proxy uri instead of the server one + forward-headers-strategy: native # =================================================================== # JHipster specific properties