allow configurable base url

This commit is contained in:
2025-07-20 12:32:23 +02:00
parent bcbdf60d73
commit 46ccdd89ff
7 changed files with 19 additions and 4 deletions
+1
View File
@@ -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
@@ -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);
@@ -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);
}
@@ -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);
}
@@ -10,7 +10,7 @@
<meta name="og:type" content="website"/>
<meta name="og:title" content="Discord Inviter"/>
<meta name="og:description" content="A simple tool to invite users to a Discord server"/>
<meta name="og:url" content="https://inviter.yht.one"/>
<meta name="og:url" content="{{base_url}}"/>
<meta name="twitter:title" content="Discord Inviter"/>
<meta name="twitter:description" content="A simple tool to invite users to a Discord server"/>
<title>Discord Inviter</title>
+2 -2
View File
@@ -10,7 +10,7 @@
<meta name="og:type" content="website"/>
<meta name="og:title" content="Discord Inviter"/>
<meta name="og:description" content="A simple tool to invite users to a Discord server"/>
<meta name="og:url" content="https://inviter.yht.one"/>
<meta name="og:url" content="{{base_url}}"/>
<meta name="twitter:title" content="Discord Inviter"/>
<meta name="twitter:description" content="A simple tool to invite users to a Discord server"/>
<title>Discord Inviter</title>
@@ -117,7 +117,7 @@
Enable developer mode
</a> in your discord client and copy your guilds ID.
</li>
<li>Now you can use <span class="highlight">https://inviter.yht.one/invite/&lt;your_guild_id&gt;</span></li>
<li>Now you can use <span class="highlight">{{base_url}}/invite/&lt;your_guild_id&gt;</span></li>
</ol>
</div>
</main>
@@ -10,7 +10,7 @@
<meta name="og:type" content="website"/>
<meta name="og:title" content="Discord Inviter"/>
<meta name="og:description" content="A simple tool to invite users to a Discord server"/>
<meta name="og:url" content="https://inviter.yht.one"/>
<meta name="og:url" content="{{base_url}}"/>
<meta name="twitter:title" content="Discord Inviter"/>
<meta name="twitter:description" content="A simple tool to invite users to a Discord server"/>
<title>Discord Inviter</title>