Skip to content

Commit

Permalink
fixup! Add Dynamic URL support
Browse files Browse the repository at this point in the history
  • Loading branch information
CE1CECL committed Dec 28, 2023
1 parent ddc425f commit fed4c8b
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ build
*.log
*.log.ansi
*.tmp
#tmp/
tmp/
dump/
3 changes: 1 addition & 2 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ server {
listen 80;

location / {
# do NOT change this
proxy_pass http://localhost:3001;
proxy_set_header Host $host;
proxy_pass_request_headers on;
Expand All @@ -23,4 +22,4 @@ server {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
}
6 changes: 5 additions & 1 deletion src/api/routes/gateway/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ router.get(
(req: Request, res: Response) => {
const { endpointPublic } = Config.get().gateway;
res.json({
url: websock || "ws://localhost:3001",
url:
endpointPublic ||
process.env.GATEWAY ||
websock ||
"ws://localhost:3001",
shards: 1,
session_start_limit: {
total: 1000,
Expand Down
6 changes: 5 additions & 1 deletion src/api/routes/gateway/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ router.get(
(req: Request, res: Response) => {
const { endpointPublic } = Config.get().gateway;
res.json({
url: websock || "ws://localhost:3001",
url:
endpointPublic ||
process.env.GATEWAY ||
websock ||
"ws://localhost:3001",
});
},
);
Expand Down
14 changes: 11 additions & 3 deletions src/api/routes/policies/instance/domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,25 @@ router.get(

const IdentityForm = {
cdn:
cdn.endpointPublic ||
process.env.CDN ||
fs.readFileSync("./tmp/PROT", { encoding: "utf8" }) +
"://" +
fs.readFileSync("./tmp/HOST", { encoding: "utf8" }) ||
"http://localhost:3001",
gateway: websock || "ws://localhost:3001",
gateway:
gateway.endpointPublic ||
process.env.GATEWAY ||
websock ||
"ws://localhost:3001",
defaultApiVersion: api.defaultVersion ?? 9,
apiEndpoint:
api.endpointPublic ||
fs.readFileSync("./tmp/PROT", { encoding: "utf8" }) +
"://" +
fs.readFileSync("./tmp/HOST", { encoding: "utf8" }) ||
"http://localhost:3001",
fs.readFileSync("./tmp/HOST", { encoding: "utf8" }) +
"/api" ||
"http://localhost:3001/api",
};

res.json(IdentityForm);
Expand Down
1 change: 1 addition & 0 deletions src/api/util/handlers/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export async function postHandleMessage(message: Message) {

// bit gross, but whatever!
const endpointPublic =
Config.get().cdn.endpointPublic ||
fs.readFileSync("./tmp/PROT", { encoding: "utf8" }) +
"://" +
fs.readFileSync("./tmp/HOST", { encoding: "utf8" }) ||
Expand Down
1 change: 1 addition & 0 deletions src/cdn/routes/attachments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ router.post(
const path = `attachments/${channel_id}/${id}/${filename}`;

const endpoint =
Config.get()?.cdn.endpointPublic ||
fs.readFileSync("./tmp/PROT", { encoding: "utf8" }) +
"://" +
fs.readFileSync("./tmp/HOST", { encoding: "utf8" }) ||
Expand Down
1 change: 1 addition & 0 deletions src/cdn/routes/avatars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ router.post(

const path = `avatars/${user_id}/${hash}`;
const endpoint =
Config.get().cdn.endpointPublic ||
fs.readFileSync("./tmp/PROT", { encoding: "utf8" }) +
"://" +
fs.readFileSync("./tmp/HOST", { encoding: "utf8" }) ||
Expand Down
1 change: 1 addition & 0 deletions src/cdn/routes/guild-profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ router.post("/", multer.single("file"), async (req: Request, res: Response) => {

const path = `guilds/${guild_id}/users/${user_id}/avatars/${hash}`;
const endpoint =
Config.get().cdn.endpointPublic ||
fs.readFileSync("./tmp/PROT", { encoding: "utf8" }) +
"://" +
fs.readFileSync("./tmp/HOST", { encoding: "utf8" }) ||
Expand Down
1 change: 1 addition & 0 deletions src/cdn/routes/role-icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ router.post(

const path = `role-icons/${role_id}/${hash}.png`;
const endpoint =
Config.get().cdn.endpointPublic ||
fs.readFileSync("./tmp/PROT", { encoding: "utf8" }) +
"://" +
fs.readFileSync("./tmp/HOST", { encoding: "utf8" }) ||
Expand Down
2 changes: 1 addition & 1 deletion src/gateway/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class Server {

if (!this.server.listening) {
this.server.listen(this.port);
console.log(`[Gateway] online on port ${this.port}`);
console.log(`[Gateway] online on 0.0.0.0:${this.port}`);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/util/connections/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export abstract class Connection {
*/
getRedirectUri() {
const endpointPublic =
Config.get().api.endpointPublic ||
fs.readFileSync("./tmp/PROT", { encoding: "utf8" }) +
"://" +
fs.readFileSync("./tmp/HOST", { encoding: "utf8" }) ||
Expand Down
10 changes: 6 additions & 4 deletions src/util/util/cdn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ export async function uploadFile(
});

const response = await fetch(
fs.readFileSync("./tmp/PROT", { encoding: "utf8" }) +
"://" +
fs.readFileSync("./tmp/HOST", { encoding: "utf8" }) +
path || "http://localhost:3001" + path,
Config.get().cdn.endpointPrivate + path ||
fs.readFileSync("./tmp/PROT", { encoding: "utf8" }) +
"://" +
fs.readFileSync("./tmp/HOST", { encoding: "utf8" }) +
path ||
"http://localhost:3001" + path,

{
headers: {
Expand Down
4 changes: 2 additions & 2 deletions src/util/util/email/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

import fs from "fs";
import fsp from "fs/promises";
import fspromises from "fs/promises";
import path from "node:path";
import { SentMessageInfo, Transporter } from "nodemailer";
import { User } from "../../entities";
Expand Down Expand Up @@ -168,7 +168,7 @@ export const Email: {
pwchange: "password_changed.html",
};

const template = await fsp.readFile(
const template = await fspromises.readFile(
path.join(
ASSET_FOLDER_PATH,
"email_templates",
Expand Down
2 changes: 1 addition & 1 deletion src/webrtc/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class Server {
await initEvent();
if (!this.server.listening) {
this.server.listen(this.port);
console.log(`[WebRTC] online on port ${this.port}`);
console.log(`[WebRTC] online on 0.0.0.0:${this.port}`);
}
}

Expand Down

0 comments on commit fed4c8b

Please sign in to comment.