Add version detection endpoint
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "adventurelog",
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.6",
|
||||
"description": "Embark, Explore, Remember. 🌍",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
27
src/routes/api/version/+server.ts
Normal file
27
src/routes/api/version/+server.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
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",
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user