diff --git a/api/src/app/routes/version/index.ts b/api/src/app/routes/version/index.ts new file mode 100644 index 0000000..2d7e1ab --- /dev/null +++ b/api/src/app/routes/version/index.ts @@ -0,0 +1,30 @@ +import type { FastifyInstance } from "fastify"; +import { readFileSync } from "fs"; +import { join } from "path"; + +interface PackageJson { + version: string; +} + +let cachedVersion: string | null = null; + +function getVersion(): string { + if (cachedVersion) { + return cachedVersion; + } + + try { + const packageJsonPath = join(process.cwd(), "package.json"); + const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8")) as PackageJson; + cachedVersion = packageJson.version; + return cachedVersion; + } catch { + return "unknown"; + } +} + +export default async function (app: FastifyInstance): Promise { + app.get("/", async (_request, reply) => { + reply.send({ version: getVersion() }); + }); +} diff --git a/apps/frontend/src/app/components/header/header.component.ts b/apps/frontend/src/app/components/header/header.component.ts index deacb42..7dad4e8 100644 --- a/apps/frontend/src/app/components/header/header.component.ts +++ b/apps/frontend/src/app/components/header/header.component.ts @@ -4,10 +4,11 @@ * @author Naomi Carrigan */ -import { Component, inject } from '@angular/core'; +import { Component, inject, signal, OnInit } from '@angular/core'; import { CommonModule } from '@angular/common'; import { RouterModule } from '@angular/router'; import { AuthService } from '../../services/auth.service'; +import { ApiService } from '../../services/api.service'; @Component({ selector: 'app-header', @@ -18,6 +19,9 @@ import { AuthService } from '../../services/auth.service';