Skip to content

Commit

Permalink
Merge pull request #605 from Frooodle/expose-port
Browse files Browse the repository at this point in the history
refactor: expose local application server port
  • Loading branch information
Frooodle authored Dec 29, 2023
2 parents 0698e28 + 34b4ae0 commit bb1d41d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
36 changes: 16 additions & 20 deletions src/main/java/stirling/software/SPDF/SPdfApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

@EnableScheduling
public class SPdfApplication {

@Autowired
private Environment env;

Expand All @@ -29,11 +29,7 @@ public void init() {

if (browserOpen) {
try {
String port = env.getProperty("local.server.port");
if(port == null || port.length() == 0) {
port="8080";
}
String url = "http://localhost:" + port;
String url = "http://localhost:" + getPort();

String os = System.getProperty("os.name").toLowerCase();
Runtime rt = Runtime.getRuntime();
Expand All @@ -46,7 +42,7 @@ public void init() {
}
}
}

public static void main(String[] args) {
SpringApplication app = new SpringApplication(SPdfApplication.class);
app.addInitializers(new ConfigInitializer());
Expand All @@ -56,28 +52,28 @@ public static void main(String[] args) {
System.out.println("External configuration file 'configs/settings.yml' does not exist. Using default configuration and environment configuration instead.");
}
app.run(args);

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

GeneralUtils.createDir("customFiles/static/");
GeneralUtils.createDir("customFiles/templates/");




System.out.println("Stirling-PDF Started.");


String url = "http://localhost:" + getPort();
System.out.println("Navigate to " + url);
}

public static String getPort() {
String port = System.getProperty("local.server.port");
if(port == null || port.length() == 0) {
port="8080";
if (port == null || port.isEmpty()) {
port = "8080";
}
String url = "http://localhost:" + port;
System.out.println("Navigate to " + url);
return port;
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
import com.fasterxml.jackson.databind.ObjectMapper;

import jakarta.servlet.ServletContext;

import stirling.software.SPDF.SPdfApplication;
import stirling.software.SPDF.model.ApiEndpoint;
import stirling.software.SPDF.model.Role;

@Service
public class ApiDocService {

Expand All @@ -28,11 +31,8 @@ public class ApiDocService {

private String getApiDocsUrl() {
String contextPath = servletContext.getContextPath();
String port = System.getProperty("local.server.port");
if(port == null || port.length() == 0) {
port="8080";
}

String port = SPdfApplication.getPort();

return "http://localhost:"+ port + contextPath + "/v1/api-docs";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.springframework.web.multipart.MultipartFile;

import jakarta.servlet.ServletContext;

import stirling.software.SPDF.SPdfApplication;
import stirling.software.SPDF.model.PipelineConfig;
import stirling.software.SPDF.model.PipelineOperation;
import stirling.software.SPDF.model.Role;
Expand Down Expand Up @@ -65,7 +67,9 @@ private String getApiKeyForUser() {

private String getBaseUrl() {
String contextPath = servletContext.getContextPath();
return "http://localhost:8080" + contextPath + "/";
String port = SPdfApplication.getPort();

return "http://localhost:" + port + contextPath + "/";
}


Expand Down

0 comments on commit bb1d41d

Please sign in to comment.