|
16 | 16 | along with this program. If not, see <https://www.gnu.org/licenses/>. |
17 | 17 | */ |
18 | 18 |
|
19 | | -import { Config, ConnectionConfig, ConnectionLoader, Email, JSONReplacer, WebAuthn, initDatabase, initEvent, registerRoutes, EnvConfig } from "@spacebar/util"; |
| 19 | +import { Config, ConnectionConfig, ConnectionLoader, Email, JSONReplacer, WebAuthn, initDatabase, initEvent, registerRoutes, EnvConfig, ErlpackType } from "@spacebar/util"; |
20 | 20 | import { Authentication, CORS, ImageProxy, BodyParser, ErrorHandler, initRateLimits, initTranslation } from "./middlewares"; |
21 | 21 | import { Request, Response, Router } from "express"; |
22 | 22 | import { Server, ServerOptions } from "lambert-server"; |
@@ -126,6 +126,42 @@ export class SpacebarServer extends Server { |
126 | 126 | res.sendFile(path.join(ASSETS_FOLDER, "openapi.json")); |
127 | 127 | }); |
128 | 128 |
|
| 129 | + // current well-known location |
| 130 | + app.get("/.well-known/spacebar", (req,res)=>{ |
| 131 | + res.json({ |
| 132 | + api: Config.get().api.endpointPublic |
| 133 | + }); |
| 134 | + }); |
| 135 | + |
| 136 | + // new well-known location |
| 137 | + app.get("/.well-known/spacebar/client", (req,res)=>{ |
| 138 | + let erlpackSupported = false; |
| 139 | + try { |
| 140 | + require("@yukikaze-bot/erlpack"); |
| 141 | + erlpackSupported = true; |
| 142 | + } catch (e) { |
| 143 | + // empty |
| 144 | + } |
| 145 | + |
| 146 | + res.json({ |
| 147 | + api: { |
| 148 | + baseUrl: Config.get().api.endpointPublic?.split("/api")[0] || "", // TODO: migrate database values to not include /api/v9 |
| 149 | + apiVersions: { |
| 150 | + default: Config.get().api.defaultVersion, |
| 151 | + active: Config.get().api.activeVersions |
| 152 | + } |
| 153 | + }, |
| 154 | + cdn: { |
| 155 | + baseUrl: Config.get().cdn.endpointPublic |
| 156 | + }, |
| 157 | + gateway: { |
| 158 | + baseUrl: Config.get().gateway.endpointPublic, |
| 159 | + encoding: [...(erlpackSupported ? ["etf"] : []), "json"], |
| 160 | + compression: ["zstd-stream", "zlib-stream", null], |
| 161 | + } |
| 162 | + }); |
| 163 | + }); |
| 164 | + |
129 | 165 | this.app.use(ErrorHandler); |
130 | 166 |
|
131 | 167 | ConnectionLoader.loadConnections(); |
|
0 commit comments