1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-08-04 12:45:17 +02:00

Refactor version API endpoint to use package.json for version detection

This commit is contained in:
Sean Morley 2024-04-20 17:32:46 +00:00
parent 172504fa66
commit ef42491421

View file

@ -1,27 +0,0 @@
import type { RequestEvent } from "@sveltejs/kit";
import { readFileSync } from "fs";
import { join, dirname } from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const packageJsonPath = join(__dirname, "..", "..", "..", "..", "package.json");
const json = readFileSync(packageJsonPath, "utf8");
const pkg = JSON.parse(json);
const version = pkg.version;
/**
* Handles the GET request for the version API endpoint.
* @param event - The request event object.
* @returns A Promise that resolves to a Response object.
*/
export async function GET(event: RequestEvent): Promise<Response> {
return new Response(JSON.stringify({ version: version }), {
status: 200,
headers: {
"Content-Type": "application/json",
},
});
}