From 73bfff34dbd669dd15ffe933b6503199ffa286d0 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 25 Apr 2025 13:26:08 +0300 Subject: [PATCH] fix(nx/docker): access to ETAPI --- apps/server/src/{etapi => assets}/etapi.openapi.yaml | 0 apps/server/src/{routes/api => assets}/openapi.json | 0 apps/server/src/etapi/spec.ts | 6 +++--- apps/server/src/routes/api_docs.ts | 10 ++++------ 4 files changed, 7 insertions(+), 9 deletions(-) rename apps/server/src/{etapi => assets}/etapi.openapi.yaml (100%) rename apps/server/src/{routes/api => assets}/openapi.json (100%) diff --git a/apps/server/src/etapi/etapi.openapi.yaml b/apps/server/src/assets/etapi.openapi.yaml similarity index 100% rename from apps/server/src/etapi/etapi.openapi.yaml rename to apps/server/src/assets/etapi.openapi.yaml diff --git a/apps/server/src/routes/api/openapi.json b/apps/server/src/assets/openapi.json similarity index 100% rename from apps/server/src/routes/api/openapi.json rename to apps/server/src/assets/openapi.json diff --git a/apps/server/src/etapi/spec.ts b/apps/server/src/etapi/spec.ts index 925ff51a6..7ef963f8f 100644 --- a/apps/server/src/etapi/spec.ts +++ b/apps/server/src/etapi/spec.ts @@ -2,13 +2,13 @@ import type { Router } from "express"; import fs from "fs"; import path from "path"; +import { RESOURCE_DIR } from "../services/resource_dir"; -import { fileURLToPath } from "url"; -const specPath = path.join(path.dirname(fileURLToPath(import.meta.url)), "etapi.openapi.yaml"); +const specPath = path.join(RESOURCE_DIR, "etapi.openapi.yaml"); let spec: string | null = null; function register(router: Router) { - router.get("/etapi/etapi.openapi.yaml", (req, res, next) => { + router.get("/etapi/etapi.openapi.yaml", (_, res) => { if (!spec) { spec = fs.readFileSync(specPath, "utf8"); } diff --git a/apps/server/src/routes/api_docs.ts b/apps/server/src/routes/api_docs.ts index 78d790bb5..122ae44b0 100644 --- a/apps/server/src/routes/api_docs.ts +++ b/apps/server/src/routes/api_docs.ts @@ -1,16 +1,14 @@ import type { Application } from "express"; import swaggerUi from "swagger-ui-express"; -import { fileURLToPath } from "url"; -import { dirname, join } from "path"; +import { join } from "path"; import yaml from "js-yaml"; import type { JsonObject } from "swagger-ui-express"; import { readFileSync } from "fs"; - -const __dirname = dirname(fileURLToPath(import.meta.url)); +import { RESOURCE_DIR } from "../services/resource_dir"; export default function register(app: Application) { - const etapiDocument = yaml.load(readFileSync(join(__dirname, "../etapi/etapi.openapi.yaml"), "utf8")) as JsonObject; - const apiDocument = JSON.parse(readFileSync(join(__dirname, "api", "openapi.json"), "utf-8")); + const etapiDocument = yaml.load(readFileSync(join(RESOURCE_DIR, "etapi.openapi.yaml"), "utf8")) as JsonObject; + const apiDocument = JSON.parse(readFileSync(join(RESOURCE_DIR, "openapi.json"), "utf-8")); app.use( "/etapi/docs/",