move all from /api, turn this into backend only ( remove ejs )
All checks were successful
Code quality checks / biome (push) Successful in 8s

This commit is contained in:
creations 2025-05-18 17:48:29 -04:00
parent 8a9499be85
commit 4936ff8978
Signed by: creations
GPG key ID: 8F553AA4320FC711
24 changed files with 14 additions and 98 deletions

View file

@ -5,6 +5,7 @@ PORT=9090
# Replace with your domain name or IP address
# If you are using a reverse proxy, set the FQDN to your domain name
FQDN=localhost:9090
FRONTEND_URL=http://localhost:8080
PGHOST=localhost
PGPORT=5432

View file

@ -2,7 +2,6 @@
"recommendations": [
"mikestead.dotenv",
"EditorConfig.EditorConfig",
"leonzalion.vscode-ejs",
"biomejs.biome"
]
}

View file

@ -18,12 +18,15 @@ const dataType: { type: string; path: string | undefined } = {
: undefined,
};
const frontendUrl: string = process.env.FRONTEND_URL || "http://localhost:8080";
function verifyRequiredVariables(): void {
const requiredVariables = [
"HOST",
"PORT",
"FQDN",
"FRONTEND_URL",
"PGHOST",
"PGPORT",
@ -58,4 +61,4 @@ function verifyRequiredVariables(): void {
export * from "@config/jwt";
export * from "@config/redis";
export { environment, dataType, verifyRequiredVariables };
export { environment, dataType, verifyRequiredVariables, frontendUrl };

View file

@ -14,7 +14,6 @@
"devDependencies": {
"@biomejs/biome": "^1.9.4",
"@types/bun": "^1.2.13",
"@types/ejs": "^3.1.5",
"@types/fluent-ffmpeg": "^2.1.27",
"@types/image-thumbnail": "^1.0.4",
"@types/luxon": "^3.6.2",
@ -26,7 +25,6 @@
},
"dependencies": {
"@creations.works/logger": "^1.0.3",
"ejs": "^3.1.10",
"eta": "^3.5.0",
"exiftool-vendored": "^30.0.0",
"fast-jwt": "6.0.1",

View file

@ -1,26 +0,0 @@
import { resolve } from "node:path";
import { renderFile } from "ejs";
export async function renderEjsTemplate(
viewName: string | string[],
data: EjsTemplateData,
headers?: Record<string, string | number | boolean>,
): Promise<Response> {
let templatePath: string;
if (Array.isArray(viewName)) {
templatePath = resolve("src", "views", ...viewName);
} else {
templatePath = resolve("src", "views", viewName);
}
if (!templatePath.endsWith(".ejs")) {
templatePath += ".ejs";
}
const html: string = await renderFile(templatePath, data);
return new Response(html, {
headers: { "Content-Type": "text/html", ...headers },
});
}

View file

@ -1,15 +0,0 @@
const routeDef: RouteDef = {
method: "GET",
accepts: "*/*",
returns: "application/json",
};
async function handler(): Promise<Response> {
// TODO: Put something useful here
return Response.json({
message: "Hello, World!",
});
}
export { handler, routeDef };

View file

@ -1,4 +1,4 @@
import { renderEjsTemplate } from "@lib/ejs";
import { frontendUrl } from "@config";
const routeDef: RouteDef = {
method: "GET",
@ -7,15 +7,14 @@ const routeDef: RouteDef = {
};
async function handler(request: ExtendedRequest): Promise<Response> {
if (!request.session) {
return Response.redirect("/auth/login");
}
const ejsTemplateData: EjsTemplateData = {
title: "Hello, World!",
};
return await renderEjsTemplate("index", ejsTemplateData);
return Response.json(
{
success: true,
code: 200,
message: `This is the api for ${frontendUrl}`,
},
{ status: 200 },
);
}
export { handler, routeDef };

View file

@ -1,31 +0,0 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="color-scheme" content="dark">
<% if (title) { %>
<title><%= title %></title>
<% } %>
<link rel="stylesheet" href="/public/css/global.css">
<% if (typeof styles !== "undefined") { %>
<% styles.forEach(style => { %>
<link rel="stylesheet" href="/public/css/<%= style %>.css">
<% }) %>
<% } %>
<% if (typeof scripts !== "undefined") { %>
<% scripts.forEach(script => { %>
<% if (typeof script === "string") { %>
<script src="/public/js/<%= script %>.js" defer></script>
<% } else if (Array.isArray(script)) { %>
<% if (script[1]) { %>
<script src="/public/js/<%= script[0] %>.js" defer></script>
<% } else { %>
<script src="/public/js/<%= script[0] %>.js"></script>
<% } %>
<% } %>
<% }) %>
<% } %>
<script src="/public/js/global.js"></script>

View file

@ -1,9 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<%- include("global", { styles: [], scripts: [] }) %>
</head>
<body>
</body>
</html>

3
types/ejs.d.ts vendored
View file

@ -1,3 +0,0 @@
interface EjsTemplateData {
[key: string]: string | number | boolean | object | undefined | null;
}