Skip to content

Commit

Permalink
Merge pull request #8827 from murdos/hardcoded-serverPort
Browse files Browse the repository at this point in the history
Fix hardcoded server port
  • Loading branch information
renanfranca authored Feb 3, 2024
2 parents bf277b0 + dea6372 commit 7bfd5fc
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tech.jhipster.lite.generator.server.springboot.thymeleaf.template.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.*;
import static tech.jhipster.lite.module.domain.packagejson.VersionSource.*;
import static tech.jhipster.lite.module.domain.packagejson.VersionSource.COMMON;

import java.util.regex.Pattern;
import tech.jhipster.lite.generator.client.common.domain.ClientsModulesFactory;
Expand Down 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:%s --files 'target/classes/templates' 'target/classes/static'".formatted(properties.serverPort())))
.addScript(scriptKey("watch:serve"), scriptCommand("browser-sync start --proxy localhost:%s --files 'target/classes/templates' 'target/classes/static'".formatted(properties.serverPort().get())))
.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:%s --files 'target/classes/templates' 'target/classes/static'".formatted(properties.serverPort())))
.addScript(scriptKey("watch:serve"), scriptCommand("browser-sync start --no-inject-changes --proxy localhost:%s --files 'target/classes/templates' 'target/classes/static'".formatted(properties.serverPort().get())))
.and()
.mandatoryReplacements()
.in(path(POSTCSS_CONFIG_JS))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {

//@formatter:off
return moduleBuilder(properties)
.context()
.put("serverPort", properties.getOrDefaultInteger("serverPort", 8080))
.and()
.files()
.batch(SOURCE, to(".devcontainer"))
.addTemplate("devcontainer.json")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package tech.jhipster.lite.generator.setup.codespaces.infrastructure.primary;

import static tech.jhipster.lite.generator.slug.domain.JHLiteModuleSlug.*;
import static tech.jhipster.lite.generator.slug.domain.JHLiteModuleSlug.GITHUB_CODESPACES;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tech.jhipster.lite.generator.setup.codespaces.application.CodespacesApplicationService;
import tech.jhipster.lite.module.domain.resource.JHipsterModulePropertiesDefinition;
import tech.jhipster.lite.module.domain.resource.JHipsterModulePropertyDefinition;
import tech.jhipster.lite.module.domain.resource.JHipsterModuleResource;

@Configuration
Expand All @@ -17,23 +16,10 @@ JHipsterModuleResource codespaceModule(CodespacesApplicationService codespaces)
return JHipsterModuleResource
.builder()
.slug(GITHUB_CODESPACES)
.propertiesDefinition(propertiesDefinition())
.propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addServerPort().build())
.apiDoc("Codespaces", "Init GitHub Codespaces configuration files")
.standalone()
.tags("setup")
.factory(codespaces::buildModule);
}

private JHipsterModulePropertiesDefinition propertiesDefinition() {
return JHipsterModulePropertiesDefinition.builder().add(serverPort()).build();
}

private JHipsterModulePropertyDefinition serverPort() {
return JHipsterModulePropertyDefinition
.optionalIntegerProperty("serverPort")
.description("Application server port")
.defaultValue("8080")
.order(200)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {
return moduleBuilder(properties)
.files()
.batch(from("setup/gitpod"), to("."))
.addFile(".gitpod.yml")
.addTemplate(".gitpod.yml")
.addFile(".gitpod.Dockerfile")
.and()
.and()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ Use the following steps to get it working:
You should now be able to change any HTML or CSS and have the browser reload upon saving the file.

NOTE: If you use a separate authentication server (e.g. social logins, or Keycloak) then after login,
you might get redirected to http://localhost:8080 as opposed to http://localhost:3000.
you might get redirected to http://localhost:{{serverPort}} as opposed to http://localhost:3000.
Be sure to set the port back to `3000` in your browser to have live reload.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ github:
addBadge: true

ports:
- port: 8080
- port: {{ serverPort }}
- port: 7471

vscode:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package tech.jhipster.lite.generator.setup.codespaces.domain;

import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.*;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.assertThatModule;

import org.junit.jupiter.api.Test;
import tech.jhipster.lite.TestFileUtils;
Expand All @@ -16,10 +16,7 @@ class CodespacesModuleFactoryTest {

@Test
void shouldBuildModule() {
JHipsterModuleProperties properties = JHipsterModulesFixture
.propertiesBuilder(TestFileUtils.tmpDirForTest())
.put("serverPort", 8080)
.build();
JHipsterModuleProperties properties = JHipsterModulesFixture.propertiesBuilder(TestFileUtils.tmpDirForTest()).build();

JHipsterModule module = factory.buildModule(properties);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package tech.jhipster.lite.generator.setup.gitpod.domain;

import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.*;
import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.assertThatModule;

import org.junit.jupiter.api.Test;
import tech.jhipster.lite.TestFileUtils;
Expand All @@ -20,6 +20,14 @@ void shouldBuildModule() {

JHipsterModule module = factory.buildModule(properties);

assertThatModule(module).hasFiles(".gitpod.yml", ".gitpod.Dockerfile");
assertThatModule(module)
.hasFile(".gitpod.yml")
.containing(
"""
port: 8080
"""
)
.and()
.hasFiles(".gitpod.Dockerfile");
}
}
1 change: 1 addition & 0 deletions tests-ci/modulePayload.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"commit": true,
"parameters": {
"projectName": "Chips Project",
"serverPort": 8081,
"baseName": "APP_NAME",
"packageName": "tech.jhipster.APP_NAME",
"jwtBase64Secret": "NmE2NDhmMmQ5OWQzYzk4NmE4NjNlMmQzNmU3ZTU4ZDY2MmUxOWEwZGI4YTk4NDY0MTk4MmQyMWZlNDNlM2FjYg==",
Expand Down
4 changes: 2 additions & 2 deletions tests-ci/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

PORT=$1
if [[ $PORT == '' ]]; then
echo "*** Using default port 8080"
PORT='8080'
echo "*** Using default port 8081"
PORT='8081'
fi

echo "*** Waiting 5sec to be sure the Jar is here"
Expand Down

0 comments on commit 7bfd5fc

Please sign in to comment.