Skip to content

Commit

Permalink
client: adjust devServerPort
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Nov 27, 2024
1 parent c9558c6 commit 412f4f6
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 38 deletions.
4 changes: 2 additions & 2 deletions generators/angular/templates/webpack/webpack.custom.js.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = async (config, options, targetOptions) => {
new BrowserSyncPlugin(
{
host: 'localhost',
port: 9000,
port: <%- devServerPortProxy %>,
https: tls,
proxy: {
target: `http${tls ? 's' : ''}://localhost:${targetOptions.target === 'serve' ? '<%= devServerPort %>' : '<%= applicationTypeMicroservice ? gatewayServerPort : serverPort %>'}`,
Expand All @@ -80,7 +80,7 @@ module.exports = async (config, options, targetOptions) => {
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-Host', 'localhost:<%- devServerPortProxy %>');
proxyReq.setHeader('X-Forwarded-Proto', 'https');
},
],
Expand Down
3 changes: 3 additions & 0 deletions generators/app/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ exports[`generator - app with default config should match snapshot 1`] = `
"devLiquibaseUrl": "jdbc:postgresql://localhost:5432/jhipster",
"devR2dbcUrl": undefined,
"devServerPort": 4200,
"devServerPortProxy": 9000,
"dockerContainers": {
"apachepulsar/pulsar": "apachepulsar-pulsar-placeholder",
"cassandra": "cassandra-placeholder",
Expand Down Expand Up @@ -991,6 +992,7 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"devLiquibaseUrl": "jdbc:postgresql://localhost:5432/jhipster",
"devR2dbcUrl": "r2dbc:postgresql://localhost:5432/jhipster",
"devServerPort": 4200,
"devServerPortProxy": 9000,
"dockerContainers": {
"apachepulsar/pulsar": "apachepulsar-pulsar-placeholder",
"cassandra": "cassandra-placeholder",
Expand Down Expand Up @@ -1651,6 +1653,7 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"devLiquibaseUrl": "jdbc:postgresql://localhost:5432/jhipster",
"devR2dbcUrl": undefined,
"devServerPort": undefined,
"devServerPortProxy": undefined,
"dockerContainers": {
"apachepulsar/pulsar": "apachepulsar-pulsar-placeholder",
"cassandra": "cassandra-placeholder",
Expand Down
14 changes: 14 additions & 0 deletions generators/client/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ const command = {
choices: ['webpack', 'vite'],
scope: 'storage',
},
devServerPort: {
cli: {
type: Number,
hide: true,
},
scope: 'storage',
},
devServerPortProxy: {
cli: {
type: Number,
hide: true,
},
scope: 'storage',
},
microfrontend: {
description: 'Enable microfrontend support',
cli: {
Expand Down
15 changes: 3 additions & 12 deletions generators/client/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,10 @@ export default class JHipsterClientGenerator extends BaseApplicationGenerator {
},

configureDevServerPort() {
if (this.jhipsterConfig.devServerPort !== undefined) return;
if (this.jhipsterConfig.devServerPort !== undefined || this.jhipsterConfig.applicationIndex === undefined) return;

const { clientFramework, applicationIndex } = this.jhipsterConfigWithDefaults;
const devServerBasePort = clientFramework === ANGULAR ? 4200 : 9060;
let devServerPort;

if (applicationIndex !== undefined) {
devServerPort = devServerBasePort + applicationIndex;
} else if (!devServerPort) {
devServerPort = devServerBasePort;
}

this.jhipsterConfig.devServerPort = devServerPort;
const { applicationIndex, devServerPort } = this.jhipsterConfigWithDefaults;
this.jhipsterConfig.devServerPort = devServerPort + applicationIndex;
},
});
}
Expand Down
3 changes: 3 additions & 0 deletions generators/docker-compose/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ export default class DockerComposeGenerator extends BaseWorkspacesGenerator {
if (appConfig.devServerPort !== undefined) {
deployment.keycloakRedirectUris += `"http://localhost:${appConfig.devServerPort}/*", `;
}
if (appConfig.devServerPortProxy !== undefined) {
deployment.keycloakRedirectUris += `"http://localhost:${appConfig.devServerPortProxy}/*", `;
}
// Split ports by ":" and take last 2 elements to skip the hostname/IP if present
const ports = yamlConfig.ports[0].split(':').slice(-2);
ports[0] = appConfig.composePort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1074,14 +1074,12 @@
<%- keycloakRedirectUris %>
"http://localhost:8100/*",
"http://127.0.0.1:8761/*",
"http://localhost:9000/*",
"dev.localhost.ionic:*"
],
"webOrigins": [
<%- keycloakRedirectUris.replace(/\/\*/g, "") %>
"http://localhost:8100",
"http://127.0.0.1:8761",
"http://localhost:9000"
"http://127.0.0.1:8761"
],
"notBefore": 0,
"bearerOnly": false,
Expand Down
3 changes: 2 additions & 1 deletion generators/java/generators/server/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default class ServerGenerator extends BaseApplicationGenerator {
});
},
packageJsonE2eScripts({ application }) {
const { devServerPort, devServerPortProxy: devServerPortE2e = devServerPort } = application;
const scriptsStorage = this.packageJson.createStorage('scripts');
const buildCmd = application.buildToolGradle ? 'gradlew' : 'mvnw -ntp';

Expand All @@ -117,7 +118,7 @@ export default class ServerGenerator extends BaseApplicationGenerator {
'ci:e2e:run': 'concurrently -k -s first -n application,e2e -c red,blue npm:ci:e2e:server:start npm:e2e:headless',
'ci:e2e:dev': `concurrently -k -s first -n application,e2e -c red,blue "./${buildCmd}" npm:e2e:headless`,
'e2e:dev': `concurrently -k -s first -n application,e2e -c red,blue "./${buildCmd}" npm:e2e`,
'e2e:devserver': `concurrently -k -s first -n backend,frontend,e2e -c red,yellow,blue npm:backend:start npm:start "wait-on -t ${WAIT_TIMEOUT} http-get://127.0.0.1:9000 && npm run e2e:headless -- -c baseUrl=http://localhost:9000"`,
'e2e:devserver': `concurrently -k -s first -n backend,frontend,e2e -c red,yellow,blue npm:backend:start npm:start "wait-on -t ${WAIT_TIMEOUT} http-get://127.0.0.1:${devServerPortE2e} && npm run e2e:headless -- -c baseUrl=http://localhost:${devServerPortE2e}"`,
});
}
},
Expand Down
16 changes: 6 additions & 10 deletions generators/kubernetes/__snapshots__/kubernetes.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3572,19 +3572,17 @@ data:
"redirectUris": [
"http://jhgate.default.example.com/*",
"https://jhgate.default.example.com/*", "http://localhost:8080/*",
"https://localhost:8080/*",
"https://localhost:8080/*","http://localhost:4200/*", "http://localhost:9000/*",
"http://localhost:8100/*",
"http://127.0.0.1:8761/*",
"http://localhost:9000/*",
"dev.localhost.ionic:*"
],
"webOrigins": [
"http://jhgate.default.example.com",
"https://jhgate.default.example.com", "http://localhost:8080",
"https://localhost:8080",
"https://localhost:8080","http://localhost:4200", "http://localhost:9000",
"http://localhost:8100",
"http://127.0.0.1:8761",
"http://localhost:9000"
"http://127.0.0.1:8761"
],
"notBefore": 0,
"bearerOnly": false,
Expand Down Expand Up @@ -7007,19 +7005,17 @@ data:
"redirectUris": [
"http://jhgate.default.example.com/*",
"https://jhgate.default.example.com/*", "http://localhost:8080/*",
"https://localhost:8080/*",
"https://localhost:8080/*","http://localhost:4200/*", "http://localhost:9000/*",
"http://localhost:8100/*",
"http://127.0.0.1:8761/*",
"http://localhost:9000/*",
"dev.localhost.ionic:*"
],
"webOrigins": [
"http://jhgate.default.example.com",
"https://jhgate.default.example.com", "http://localhost:8080",
"https://localhost:8080",
"https://localhost:8080","http://localhost:4200", "http://localhost:9000",
"http://localhost:8100",
"http://127.0.0.1:8761",
"http://localhost:9000"
"http://127.0.0.1:8761"
],
"notBefore": 0,
"bearerOnly": false,
Expand Down
3 changes: 3 additions & 0 deletions generators/kubernetes/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ export function writeFiles() {
if (appConfig.devServerPort !== undefined) {
this.keycloakRedirectUris += `"http://localhost:${appConfig.devServerPort}/*", `;
}
if (appConfig.devServerPortProxy !== undefined) {
this.keycloakRedirectUris += `"http://localhost:${appConfig.devServerPortProxy}/*", `;
}

this.debug(chalk.red.bold(`${appConfig.baseName} has redirect URIs ${this.keycloakRedirectUris}`));
this.debug(chalk.red.bold(`AppConfig is ${JSON.stringify(appConfig)}`));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1038,14 +1038,12 @@ data:
<%- keycloakRedirectUris %>
"http://localhost:8100/*",
"http://127.0.0.1:8761/*",
"http://localhost:9000/*",
"dev.localhost.ionic:*"
],
"webOrigins": [
<%- keycloakRedirectUris.replace(/\/\*/g, "") %>
"http://localhost:8100",
"http://127.0.0.1:8761",
"http://localhost:9000"
"http://127.0.0.1:8761"
],
"notBefore": 0,
"bearerOnly": false,
Expand Down
2 changes: 1 addition & 1 deletion generators/react/templates/webpack/webpack.dev.js.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ module.exports = async (options) => webpackMerge(await commonConfig({ env: ENV }
{
https: options.tls,
host: 'localhost',
port: 9000,
port: <%- devServerPortProxy %>,
proxy: {
target: `http${options.tls ? 's' : ''}://localhost:${options.watch ? '<%= applicationTypeMicroservice ? gatewayServerPort : serverPort %>' : '<%= devServerPort %>'}`,
ws: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ jhipster:
<%_ if (microfrontend) { _%>
# Ports <%= devServerPort + 1 %>-<%= devServerPort + 9 %> are allowed for microfrontend development
<%_ } _%>
allowed-origins: "http://localhost:8100,https://localhost:8100,http://localhost:9000,https://localhost:9000<%_ if (!skipClient) { _%>,http://localhost:<%= devServerPort %>,https://localhost:<%= devServerPort %><%_ if (microfrontend) { for (let port = 1; port < 10; port++) { _%>,http://localhost:<%= devServerPort + port %>,https://localhost:<%= devServerPort + port %><%_ } _%><%_ } } _%>"
allowed-origins: "http://localhost:8100,https://localhost:8100<%_ if (devServerPortProxy) { _%>,http://localhost:<%= devServerPortProxy %>,https://localhost:<%= devServerPortProxy %><%_ } _%><%_ if (!skipClient) { _%>,http://localhost:<%= devServerPort %>,https://localhost:<%= devServerPort %><%_ if (microfrontend) { for (let port = 1; port < 10; port++) { _%>,http://localhost:<%= devServerPort + port %>,https://localhost:<%= devServerPort + port %><%_ } _%><%_ } } _%>"
# Enable CORS when running in GitHub Codespaces
allowed-origin-patterns: 'https://*.githubpreview.dev'
allowed-methods: "*"
Expand Down
17 changes: 17 additions & 0 deletions generators/vue/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ export default class VueGenerator extends BaseApplicationGenerator {
}
}

get configuring() {
return this.asConfiguringTaskGroup({
configureDevServerPort() {
if (this.jhipsterConfig.devServerPort === undefined) return;
if (this.isJhipsterVersionLessThan('8.7.4')) {
// Migrate old devServerPort with new one
const { applicationIndex = 0 } = this.jhipsterConfigWithDefaults;
this.jhipsterConfig.devServerPort = 9000 + applicationIndex;
}
},
});
}

get [BaseApplicationGenerator.CONFIGURING]() {
return this.delegateTasksToBlueprint(() => this.configuring);
}

get loading() {
return this.asLoadingTaskGroup({
loadPackageJson({ application }) {
Expand Down
2 changes: 1 addition & 1 deletion generators/vue/templates/vite.config.mts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ let config = defineConfig({
},
server: {
host: true,
port: 9000,
port: <%- devServerPort %>,
proxy: Object.fromEntries(
[
'/api',
Expand Down
2 changes: 1 addition & 1 deletion generators/vue/templates/webpack/webpack.dev.js.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = (env, options) => {
new BrowserSyncPlugin(
{
host: 'localhost',
port: 9000,
port: <%- devServerPortProxy %>,
proxy: {
target: `http://localhost:${options.watch ? '<%= applicationTypeMicroservice ? gatewayServerPort : serverPort %>' : '<%= devServerPort %>'}`,
ws: true,
Expand Down
13 changes: 10 additions & 3 deletions lib/jhipster/default-application-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,19 @@ export function getConfigForClientApplication(options: ApplicationDefaults = {})
options[CLIENT_THEME_VARIANT] = 'primary';
}
if (clientFramework === 'vue') {
options.clientBundler = options.microfrontend || options.applicationType === 'microservice' ? 'webpack' : 'vite';
options.clientBundler ??= options.microfrontend || options.applicationType === 'microservice' ? 'webpack' : 'vite';
options.devServerPort ??= options.clientBundler === 'webpack' ? 9060 : 9000;
} else if (clientFramework === 'react') {
options.clientBundler = 'webpack';
options.clientBundler ??= 'webpack';
options.devServerPort ??= 9060;
} else if (clientFramework === 'angular') {
options.clientBundler = 'webpack';
options.clientBundler ??= 'webpack';
options.devServerPort ??= 4200;
} else {
options.devServerPort ??= 9060;
}
options.devServerPortProxy ??= options.clientBundler === 'webpack' ? 9000 : undefined;

return options;
}

Expand Down

0 comments on commit 412f4f6

Please sign in to comment.