diff --git a/generators/angular/files-angular.ts b/generators/angular/files-angular.ts index 87680b5274eb..23b3311f7e49 100644 --- a/generators/angular/files-angular.ts +++ b/generators/angular/files-angular.ts @@ -59,7 +59,7 @@ export const files = { condition: ctx => ctx.clientBundlerExperimentalEsbuild, templates: [ { sourceFile: 'angular.json.esbuild', destinationFile: 'angular.json' }, - 'proxy.conf.json', + 'proxy.config.mjs', 'build-plugins/define-esbuild.mjs', ], }), diff --git a/generators/angular/templates/angular.json.esbuild.ejs b/generators/angular/templates/angular.json.esbuild.ejs index cafd9605e0e1..096af7e8f8f7 100644 --- a/generators/angular/templates/angular.json.esbuild.ejs +++ b/generators/angular/templates/angular.json.esbuild.ejs @@ -126,7 +126,7 @@ "options": { "buildTarget": "<%= dasherizedBaseName %>:build:development", "open": true, - "proxyConfig": "proxy.conf.json", + "proxyConfig": "proxy.config.mjs", "port": <%= devServerPort %> }, "configurations": { diff --git a/generators/angular/templates/proxy.conf.json.ejs b/generators/angular/templates/proxy.conf.json.ejs deleted file mode 100644 index deb20ebae515..000000000000 --- a/generators/angular/templates/proxy.conf.json.ejs +++ /dev/null @@ -1,27 +0,0 @@ -<%# - Copyright 2013-2024 the original author or authors from the JHipster project. - - This file is part of the JHipster project, see https://www.jhipster.tech/ - for more information. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --%> -{ -<%_ if (communicationSpringWebsocket) { _%> - "/websocket": { - "target": "ws://localhost:8080", - "ws": true - }, -<%_ } _%> - "^/(api|management|v3/api-docs<% if (databaseTypeSql && devDatabaseTypeH2Any) { %>|h2-console<% } %><% if (authenticationTypeOauth2) { %>|oauth2|login<% } %><% if (authenticationTypeSession) { %>|login<% } %><% if (applicationTypeGateway || applicationTypeMicroservice) { %>|services<% } %>)": "http://localhost:<%= applicationTypeMicroservice ? gatewayServerPort : serverPort %>" -} diff --git a/generators/angular/templates/proxy.config.mjs.ejs b/generators/angular/templates/proxy.config.mjs.ejs new file mode 100644 index 000000000000..7dbcab98c869 --- /dev/null +++ b/generators/angular/templates/proxy.config.mjs.ejs @@ -0,0 +1,24 @@ +const backendHost = '127.0.0.1'; +const backendPort = <%= applicationTypeMicroservice ? gatewayServerPort : serverPort %>; + +<%_ if (clientBundlerExperimentalEsbuild) { _%> +/** + * @type {import('vite').CommonServerOptions['proxy']} + */ +<%_ } _%> +export default { +<%_ if (communicationSpringWebsocket) { _%> + '/websocket': { + target: `ws://${backendHost}:${backendPort}`, + ws: true, + }, +<%_ } _%> + '^/(api|management|v3/api-docs<% if (databaseTypeSql && devDatabaseTypeH2Any) { %>|h2-console<% } %><% if (authenticationTypeOauth2) { %>|oauth2|login<% } %><% if (authenticationTypeSession) { %>|login<% } %><% if (applicationTypeGateway || applicationTypeMicroservice) { %>|services<% } %>)': { +<%_ if (clientBundlerExperimentalEsbuild) { _%> + target: `http://${backendHost}:${backendPort}`, +<%_ } else { _%> + router: req => `http${req.socket.ssl ? 's' : ''}://${backendHost}:${backendPort}`, +<%_ } _%> + xfwd: true, + }, +};