Skip to content

Commit de30cd4

Browse files
Add well-known routes
1 parent 28cfb6b commit de30cd4

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

.idea/workspace.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api/Server.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
1818

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";
2020
import { Authentication, CORS, ImageProxy, BodyParser, ErrorHandler, initRateLimits, initTranslation } from "./middlewares";
2121
import { Request, Response, Router } from "express";
2222
import { Server, ServerOptions } from "lambert-server";
@@ -126,6 +126,42 @@ export class SpacebarServer extends Server {
126126
res.sendFile(path.join(ASSETS_FOLDER, "openapi.json"));
127127
});
128128

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+
129165
this.app.use(ErrorHandler);
130166

131167
ConnectionLoader.loadConnections();

0 commit comments

Comments
 (0)