mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
feat(frontend): ✨ Allow usage of glitch-soc as frontend (alpha)
This commit is contained in:
parent
1aacf7d743
commit
ff6a91f916
7 changed files with 81 additions and 1 deletions
|
|
@ -123,6 +123,17 @@ export interface Config {
|
|||
frontend: {
|
||||
/** @default "http://localhost:3000" */
|
||||
url: string;
|
||||
|
||||
glitch: {
|
||||
/** @default false */
|
||||
enabled: boolean;
|
||||
|
||||
/** @default "glitch" */
|
||||
assets: string;
|
||||
|
||||
/** @default [] */
|
||||
server: string[];
|
||||
};
|
||||
};
|
||||
|
||||
smtp: {
|
||||
|
|
@ -437,6 +448,11 @@ export const defaultConfig: Config = {
|
|||
},
|
||||
frontend: {
|
||||
url: "http://localhost:3000",
|
||||
glitch: {
|
||||
enabled: false,
|
||||
assets: "glitch",
|
||||
server: [],
|
||||
},
|
||||
},
|
||||
smtp: {
|
||||
server: "smtp.example.com",
|
||||
|
|
|
|||
37
packages/glitch-server/main.ts
Normal file
37
packages/glitch-server/main.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import { dualLogger } from "@loggers";
|
||||
import { errorResponse } from "@response";
|
||||
import { config } from "config-manager";
|
||||
import { join } from "node:path";
|
||||
import {
|
||||
LogLevel,
|
||||
type LogManager,
|
||||
type MultiLogManager,
|
||||
} from "~packages/log-manager";
|
||||
|
||||
export const handleGlitchRequest = async (
|
||||
req: Request,
|
||||
logger: LogManager | MultiLogManager,
|
||||
): Promise<Response> => {
|
||||
const url = new URL(req.url);
|
||||
let path = url.pathname;
|
||||
|
||||
// Strip leading /web from path
|
||||
if (path.startsWith("/web")) path = path.slice(4);
|
||||
|
||||
// Redirect / to /index.html
|
||||
if (path === "/" || path === "") path = "/index.html";
|
||||
// If path doesn't have an extension (e.g. /about), serve index.html
|
||||
// Also check if Accept header contains text/html
|
||||
if (!path.includes(".") && req.headers.get("Accept")?.includes("text/html"))
|
||||
path = "/index.html";
|
||||
|
||||
const file = Bun.file(join(config.frontend.glitch.assets, path));
|
||||
|
||||
if (await file.exists()) {
|
||||
return new Response(file);
|
||||
}
|
||||
|
||||
dualLogger.log(LogLevel.WARNING, "Glitch-Soc", `Asset not found: ${path}`);
|
||||
|
||||
return errorResponse("Glitch-Soc route not found", 404);
|
||||
};
|
||||
6
packages/glitch-server/package.json
Normal file
6
packages/glitch-server/package.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "glitch-server",
|
||||
"version": "0.0.0",
|
||||
"main": "index.ts",
|
||||
"dependencies": {}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue