Skip to content

Commit

Permalink
add endpoint to get live url
Browse files Browse the repository at this point in the history
  • Loading branch information
targoninc-alex committed May 27, 2024
1 parent 7ca4871 commit 1f5fcc5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/features/live/endpoints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Request, Response } from "express";

export class LiveEndpoints {
static getWebsocketEndpoint() {
return (req: Request, res: Response, next: Function) => {
const url = process.env.WEBSOCKET_URL ?? "ws://127.0.0.1:8912";
res.send(url);
}
}
}
5 changes: 4 additions & 1 deletion src/features/liveFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import {MariaDbDatabase} from "./database/mariaDbDatabase";
import {ServerOptions, WebSocketServer} from "ws";
import {MessagingEndpoints} from "./messaging/endpoints";
import {CLI} from "../tooling/CLI";
import {Message, User} from "./database/models";
import {User} from "./database/models";
import {Application} from "express";
import {createServer} from "http";
import {UserWebSocket} from "./live/UserWebSocket";
import {safeUser} from "./authentication/actions";
import {PermissionsList} from "../enums/permissionsList";
import {LiveEndpoints} from "./live/endpoints";

export class LiveFeature {
static enable(app: Application, userMap: Map<string, User>, db: MariaDbDatabase) {
app.get("/api/live/url", LiveEndpoints.getWebsocketEndpoint());

const server = createServer(app);
const wss = new WebSocketServer({
noServer: true
Expand Down
29 changes: 28 additions & 1 deletion src/swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,34 @@ export const swaggerOptions = {
}
]
}
}
},
"/api/live/url": {
get: {
summary: "Get the websocket URL",
tags: [
"Live"
],
description: "Get the websocket URL",
responses: {
200: {
description: "Websocket URL retrieved successfully",
content: {
'application/json': {
schema: {
type: "object",
properties: {
url: {
type: "string",
description: "The websocket URL"
}
}
}
}
}
}
}
}
},
},
components: {
schemas: {
Expand Down
2 changes: 1 addition & 1 deletion tools/apiBuilder.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from "fs";
import {swaggerOptions} from "../src/swagger.js";
import {swaggerOptions} from "../src/swagger.ts";

const start = `import {ApiBase} from "./ApiBase.mjs";
Expand Down

0 comments on commit 1f5fcc5

Please sign in to comment.