diff --git a/docker-composer.override.example.yml b/docker-composer.override.example.yml index 6f7c04a..b6fd4d4 100644 --- a/docker-composer.override.example.yml +++ b/docker-composer.override.example.yml @@ -7,3 +7,4 @@ services: # - ./logs:/app/logs # uncomment to get access to logs more easily environment: DISCORD_TOKEN: "your_discord_token_here" + BASE_URL: "https://example.com" # replace with your actual base URL. THis will display on the template pages diff --git a/src/main/java/me/youhavetrouble/inviter/Main.java b/src/main/java/me/youhavetrouble/inviter/Main.java index 2e347a5..9df7b82 100644 --- a/src/main/java/me/youhavetrouble/inviter/Main.java +++ b/src/main/java/me/youhavetrouble/inviter/Main.java @@ -22,6 +22,8 @@ public class Main { public static final Logger LOGGER = LoggerFactory.getLogger("Inviter"); + public static String baseUrl; + private static JDA jda; private static DiscordInviteManager discordInviteManager; private static ApiServer apiServer; @@ -31,6 +33,15 @@ public class Main { String token = System.getenv("DISCORD_TOKEN"); + String baseUrlRaw = System.getenv("BASE_URL"); + if (baseUrlRaw == null || baseUrlRaw.isEmpty()) { + baseUrl = "https://example.com"; + LOGGER.warn("BASE_URL environment variable is not set. Using default: {}", baseUrl); + } else { + if (baseUrlRaw.endsWith("/")) baseUrlRaw = baseUrlRaw.substring(0, baseUrlRaw.length() - 1); + baseUrl = baseUrlRaw; + } + if (token == null || token.isEmpty()) { LOGGER.error("Discord token is not set. Please set the DISCORD_TOKEN environment variable."); System.exit(1); diff --git a/src/main/java/me/youhavetrouble/inviter/http/endpoints/GetDiscordInviteByGuildId.java b/src/main/java/me/youhavetrouble/inviter/http/endpoints/GetDiscordInviteByGuildId.java index b10d412..d52fed9 100644 --- a/src/main/java/me/youhavetrouble/inviter/http/endpoints/GetDiscordInviteByGuildId.java +++ b/src/main/java/me/youhavetrouble/inviter/http/endpoints/GetDiscordInviteByGuildId.java @@ -26,6 +26,7 @@ public class GetDiscordInviteByGuildId implements EndpointHandler { try (InputStream resource = this.getClass().getResourceAsStream("/template/invites-paused.html")) { assert resource != null; invitesDisabledTemplate = new String(resource.readAllBytes()); + invitesDisabledTemplate = invitesDisabledTemplate.replaceAll("\\{\\{base_url}}", Main.baseUrl); } catch (IOException | NullPointerException e) { Main.LOGGER.warn("Failed to load template for invites disabled page", e); } @@ -35,6 +36,7 @@ public class GetDiscordInviteByGuildId implements EndpointHandler { try (InputStream resource = this.getClass().getResourceAsStream("/template/guild-not-supported.html")) { assert resource != null; botNotInGuildTemplate = new String(resource.readAllBytes()); + botNotInGuildTemplate = botNotInGuildTemplate.replaceAll("\\{\\{base_url}}", Main.baseUrl); } catch (IOException | NullPointerException e) { Main.LOGGER.warn("Failed to load template for guild not supported page", e); } diff --git a/src/main/java/me/youhavetrouble/inviter/http/endpoints/MainEndpoint.java b/src/main/java/me/youhavetrouble/inviter/http/endpoints/MainEndpoint.java index 88cc1a1..34794b8 100644 --- a/src/main/java/me/youhavetrouble/inviter/http/endpoints/MainEndpoint.java +++ b/src/main/java/me/youhavetrouble/inviter/http/endpoints/MainEndpoint.java @@ -20,6 +20,7 @@ public class MainEndpoint implements EndpointHandler { try (InputStream resource = this.getClass().getResourceAsStream("/template/index.html")) { rawTemplate = new String(resource.readAllBytes()); rawTemplate = rawTemplate.replaceAll("\\{\\{discord_app_id}}", Main.getJda().getSelfUser().getApplicationId()); + rawTemplate = rawTemplate.replaceAll("\\{\\{base_url}}", Main.baseUrl); } catch (IOException | NullPointerException e) { Main.LOGGER.warn("Failed to load template for main endpoint", e); } diff --git a/src/main/resources/template/guild-not-supported.html b/src/main/resources/template/guild-not-supported.html index d08fe3d..46a60b1 100644 --- a/src/main/resources/template/guild-not-supported.html +++ b/src/main/resources/template/guild-not-supported.html @@ -10,7 +10,7 @@ - +