From 81fac6b90b9f6c0e2244668de694ac900c85279b Mon Sep 17 00:00:00 2001 From: Ushie Date: Sat, 25 Feb 2023 01:19:34 +0300 Subject: [PATCH] fix(callback): check and remove trailing slash in WEB_URL (#39) * fix(callback): check and remove trailing slash in WEB_URL --------- Co-authored-by: Khakers <22665282+khakers@users.noreply.github.com> --- .../java/com/github/khakers/modmailviewer/Config.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/khakers/modmailviewer/Config.java b/src/main/java/com/github/khakers/modmailviewer/Config.java index a0d0dba6..e1bbe822 100644 --- a/src/main/java/com/github/khakers/modmailviewer/Config.java +++ b/src/main/java/com/github/khakers/modmailviewer/Config.java @@ -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 @@ -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()) { @@ -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 notNullObjOrElse(T obj, T defaultObj) {