Skip to content

Commit

Permalink
fix(callback): check and remove trailing slash in WEB_URL (#39)
Browse files Browse the repository at this point in the history
* fix(callback): check and remove trailing slash in WEB_URL

---------

Co-authored-by: Khakers <[email protected]>
  • Loading branch information
Ushie and khakers authored Feb 24, 2023
1 parent 705a932 commit 81fac6b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/com/github/khakers/modmailviewer/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Config {

public static final String MONGODB_URI = Assert.requireNonEmpty(System.getenv(ENV_PREPEND + "_MONGODB_URI"), "No mongodb URI provided. provide one with the option \""+ENV_PREPEND+"_MONGODB_URI\"");

public static final String WEB_URL = Assert.requireNonEmpty(System.getenv(ENV_PREPEND + "_URL"), "No URL provided. provide one with the option \""+ENV_PREPEND+"_URL\"");
public static final String WEB_URL;

public static final boolean isSecure = isSetToTrue(System.getenv(ENV_PREPEND + "_SSL"));
@Nullable
Expand Down Expand Up @@ -54,7 +54,6 @@ public class Config {

public static final String BRANDING = notEmptyOrElse(System.getenv(ENV_PREPEND + "_BRANDING"), "Modmail-Viewer");


static {
var jwtSecretKey = System.getenv("MODMAIL_VIEWER_SECRETKEY");
if (jwtSecretKey == null || jwtSecretKey.isEmpty()) {
Expand All @@ -66,6 +65,13 @@ public class Config {
} else {
JWT_SECRET_KEY = jwtSecretKey;
}

var webUrl = Assert.requireNonEmpty(System.getenv(ENV_PREPEND + "_URL"), "No URL provided. provide one with the option \"" + ENV_PREPEND + "_URL\"");
if (webUrl.endsWith("/")) {
logger.warn(ENV_PREPEND + "_WEB_URL has a trailing slash. Removed it due to conflict with the callback.");
webUrl = webUrl.substring(0, webUrl.length() - 1);
}
WEB_URL = webUrl;
}

private static <T> T notNullObjOrElse(T obj, T defaultObj) {
Expand Down

0 comments on commit 81fac6b

Please sign in to comment.