Skip to content

Commit

Permalink
Merge pull request #8825 from alerGeek/fix/IS-8824-replace-default-se…
Browse files Browse the repository at this point in the history
…rver-port-when-property-custom

replace default server port when property has custom value
  • Loading branch information
murdos authored Feb 3, 2024
2 parents af7e039 + f6d69a3 commit bf277b0
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {
.add(SOURCE.file("tsconfig.json"), to("tsconfig.json"))
.add(SOURCE.file("tsconfig.app.json"), to("tsconfig.app.json"))
.add(SOURCE.file("tsconfig.spec.json"), to("tsconfig.spec.json"))
.add(SOURCE.file("proxy.conf.json"), to("proxy.conf.json"))
.add(SOURCE.file(".eslintrc.json"), to(".eslintrc.json"))
.add(COMMON_ESLINT.file(".eslintignore"), to(".eslintignore"))
.batch(SOURCE, to("."))
.addTemplate("proxy.conf.json")
.and()
.batch(SOURCE.file("src/main/webapp/app"), to("src/main/webapp/app"))
.addTemplate("app.component.ts")
.addTemplate("app.component.css")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {
.files()
.batch(SOURCE, to("."))
.addFile("tsconfig.json")
.addFile("vite.config.ts")
.addTemplate("vite.config.ts")
.addFile("vitest.config.ts")
.addFile(".eslintrc.cjs")
.and()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {
.addScript(scriptKey("watch:css"), scriptCommand("onchange 'src/main/resources/static/css/**/*.css' -- npm run build:css"))
.addScript(scriptKey("watch:js"), scriptCommand("onchange 'src/main/resources/static/js/**/*.js' -- npm run build:js"))
.addScript(scriptKey("watch:svg"), scriptCommand("onchange 'src/main/resources/static/svg/**/*.svg' -- npm run build:svg"))
.addScript(scriptKey("watch:serve"), scriptCommand("browser-sync start --proxy localhost:8080 --files 'target/classes/templates' 'target/classes/static'"))
.addScript(scriptKey("watch:serve"), scriptCommand("browser-sync start --proxy localhost:%s --files 'target/classes/templates' 'target/classes/static'".formatted(properties.serverPort())))
.and()
.files()
.add(RESOURCES_SOURCE.append(TEMPLATES).template("index.html"), toSrcMainResources().append(TEMPLATES).append("index.html"))
Expand All @@ -132,7 +132,7 @@ public JHipsterModule buildTailwindcssModule(JHipsterModuleProperties properties
.packageJson()
.addDevDependency(packageName("tailwindcss"), COMMON)
.addScript(scriptKey("watch:html"), scriptCommand("onchange 'src/main/resources/templates/**/*.html' -- npm-run-all --serial build:css build:html"))
.addScript(scriptKey("watch:serve"), scriptCommand("browser-sync start --no-inject-changes --proxy localhost:8080 --files 'target/classes/templates' 'target/classes/static'"))
.addScript(scriptKey("watch:serve"), scriptCommand("browser-sync start --no-inject-changes --proxy localhost:%s --files 'target/classes/templates' 'target/classes/static'".formatted(properties.serverPort())))
.and()
.mandatoryReplacements()
.in(path(POSTCSS_CONFIG_JS))
Expand Down
10 changes: 0 additions & 10 deletions src/main/resources/generator/client/angular/core/proxy.conf.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"/api": {
"target": "http://localhost:{{serverPort}}",
"secure": false
},
"/management": {
"target": "http://localhost:{{serverPort}}",
"secure": false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default defineConfig({
hmr: { overlay: false },
proxy: {
'/api': {
target: 'http://localhost:8080',
target: 'http://localhost:{{serverPort}}',
changeOrigin: true,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The basic auth just allows you to authenticate one user configured in `applicati
## How it works

- Be sure to have selected and applied the `springdoc-jwt` module
- Access the swagger url: [http://localhost:8080/swagger-ui/index.html#](http://localhost:8080/swagger-ui/index.html#)
- Access the swagger url: [http://localhost:{{serverPort}}/swagger-ui/index.html#](http://localhost:{{serverPort}}/swagger-ui/index.html#)
- Execute the `POST /api/authenticate` endpoint passing the username and password to retrieve the token
- Enter only the token after clicking on the `Authorize` button at the top right
- Execute the `GET /api/account` to test if the token works
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,8 @@
{
"id": "6e8deddb-b4d6-4e2e-b389-b397d3f74fcd",
"clientId": "web_app",
"rootUrl": "http://localhost:8080",
"adminUrl": "http://localhost:8080",
"rootUrl": "http://localhost:{{serverPort}}",
"adminUrl": "http://localhost:{{serverPort}}",
"surrogateAuthRequired": false,
"enabled": true,
"alwaysDisplayInConsole": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,32 @@ void shouldCreateAngularModule() {
)
.hasPrefixedFiles("src/main/webapp", "index.html", "main.ts", "styles.css");
}

@Test
void shouldProxyBeUpdatedWhenServerPortPropertyNotDefault() {
JHipsterModuleProperties properties = JHipsterModulesFixture
.propertiesBuilder(TestFileUtils.tmpDirForTest())
.projectBaseName("jhiTest")
.put("serverPort", 8081)
.build();

JHipsterModule module = factory.buildModule(properties);
assertThatModuleWithFiles(module, packageJsonFile(), lintStagedConfigFile())
.hasFile("proxy.conf.json")
.containing("\"target\": \"http://localhost:8081\"")
.notContaining("\"target\": \"http://localhost:8080\"");
}

@Test
void shouldProxyBeDefaultWhenServerPortPropertyMissing() {
JHipsterModuleProperties properties = JHipsterModulesFixture
.propertiesBuilder(TestFileUtils.tmpDirForTest())
.projectBaseName("jhiTest")
.build();

JHipsterModule module = factory.buildModule(properties);
assertThatModuleWithFiles(module, packageJsonFile(), lintStagedConfigFile())
.hasFile("proxy.conf.json")
.containing("\"target\": \"http://localhost:8080\"");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@ void shouldBuildModuleWithStyle() {
.hasPrefixedFiles("src/main/webapp/assets", "ReactLogo.png", "JHipster-Lite-neon-blue.png");
}

@Test
void shouldViteConfigBeUpdatedWhenServerPortPropertyNotDefault() {
JHipsterModule module = factory.buildModule(
JHipsterModulesFixture.propertiesBuilder(TestFileUtils.tmpDirForTest()).projectBaseName("jhipster").put("serverPort", 8081).build()
);

assertThatModuleWithFiles(module, packageJsonFile())
.hasFile("vite.config.ts")
.containing("localhost:8081")
.notContaining("localhost:8080");
}

@Test
void shouldViteConfigBeDefaultWhenServerPortPropertyMissing() {
JHipsterModule module = factory.buildModule(
JHipsterModulesFixture.propertiesBuilder(TestFileUtils.tmpDirForTest()).projectBaseName("jhipster").build()
);

assertThatModuleWithFiles(module, packageJsonFile()).hasFile("vite.config.ts").containing("localhost:8080");
}

private String nodeScript(String key, String value) {
return "\"" + key + "\": \"" + value + "\"";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,24 @@ void shouldCreateTailwindcssModule() {
//@formatter:on
}

@Test
void shouldProxyBeUpdatedWhenServerPortPropertyNotDefault() {
JHipsterModuleProperties properties = JHipsterModulesFixture
.propertiesBuilder(TestFileUtils.tmpDirForTest())
.projectBaseName("jhipster")
.put("serverPort", 8081)
.build();

JHipsterModule module = factory.buildModule(properties);

//@formatter:off
assertThatModuleWithFiles(module, packageJsonFile())
.hasFile("package.json")
.containing("browser-sync start --proxy localhost:8081 --files 'target/classes/templates' 'target/classes/static'")
.notContaining("browser-sync start --proxy localhost:8080 --files 'target/classes/templates' 'target/classes/static'");
//@formatter:on
}

private static ModuleFile appPostcssFile() {
return new ModuleFile("src/test/resources/projects/thymeleaf/postcss.config.js.template", "postcss.config.js");
}
Expand Down

0 comments on commit bf277b0

Please sign in to comment.