Skip to content

Commit 345f0be

Browse files
Merge pull request #151 from spammenotinoz/main
modification so that a GET request to “/openapi.yaml” returns the openapi.yaml
2 parents 68bdd56 + c8d2b02 commit 345f0be

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

esbuild.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,8 @@ esbuild
5151
sourcemap: prod ? false : "inline",
5252
treeShaking: true,
5353
outfile: "main.js",
54+
loader: {
55+
".yaml": "text", // Added to handle handle .yaml files as text
56+
},
5457
})
5558
.catch(() => process.exit(1));

src/declarations.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module "*.yaml" {
2+
const content: string;
3+
export default content;
4+
}

src/requestHandler.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ import {
5656
} from "./constants";
5757
import LocalRestApiPublicApi from "./api";
5858

59+
// Import openapi.yaml as a string
60+
import openapiYaml from "../docs/openapi.yaml";
61+
5962
export default class RequestHandler {
6063
app: App;
6164
api: express.Express;
@@ -255,10 +258,10 @@ export default class RequestHandler {
255258
certificateInfo:
256259
this.requestIsAuthenticated(req) && certificate
257260
? {
258-
validityDays: getCertificateValidityDays(certificate),
259-
regenerateRecommended:
260-
!getCertificateIsUptoStandards(certificate),
261-
}
261+
validityDays: getCertificateValidityDays(certificate),
262+
regenerateRecommended:
263+
!getCertificateIsUptoStandards(certificate),
264+
}
262265
: undefined,
263266
apiExtensions: this.requestIsAuthenticated(req)
264267
? this.apiExtensions.map(({ manifest }) => manifest)
@@ -1173,6 +1176,12 @@ export default class RequestHandler {
11731176
}
11741177

11751178
setupRouter() {
1179+
// Serve /openapi.yaml unauthenticated
1180+
this.api.get("/openapi.yaml", (req, res) => {
1181+
res.setHeader("Content-Type", "application/yaml; charset=utf-8");
1182+
res.status(200).send(openapiYaml);
1183+
});
1184+
11761185
this.api.use((req, res, next) => {
11771186
const originalSend = res.send;
11781187
res.send = function (body, ...args) {

0 commit comments

Comments
 (0)