Added basic loaders/files/dirs
This commit is contained in:
11
src/loaders/express.ts
Normal file
11
src/loaders/express.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Application } from "express";
|
||||
/**
|
||||
* Loader for express related configurations.
|
||||
* Configures proxy trusts, globally used middlewares and other express features.
|
||||
*/
|
||||
export default async (app: Application) => {
|
||||
app.enable('trust proxy');
|
||||
app.disable('x-powered-by');
|
||||
app.disable('x-served-by');
|
||||
return app;
|
||||
};
|
||||
13
src/loaders/index.ts
Normal file
13
src/loaders/index.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Application } from "express";
|
||||
import expressLoader from "./express";
|
||||
import openapiLoader from "./openapi";
|
||||
|
||||
/**
|
||||
* Index Loader that executes the other loaders in the right order.
|
||||
* This basicly exists for abstraction and a overall better dev experience.
|
||||
*/
|
||||
export default async (app: Application) => {
|
||||
await openapiLoader(app);
|
||||
await expressLoader(app);
|
||||
return app;
|
||||
};
|
||||
24
src/loaders/openapi.ts
Normal file
24
src/loaders/openapi.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { validationMetadatasToSchemas } from "@odit/class-validator-jsonschema";
|
||||
import express, { Application } from "express";
|
||||
import path from 'path';
|
||||
import { getMetadataArgsStorage } from "routing-controllers";
|
||||
import { generateSpec } from '../apispec';
|
||||
|
||||
/**
|
||||
* Loader for everything openapi related - from creating the schema to serving it via a static route and swaggerUiExpress.
|
||||
* All auth schema related stuff also has to be configured here
|
||||
*/
|
||||
export default async (app: Application) => {
|
||||
const storage = getMetadataArgsStorage();
|
||||
const schemas = validationMetadatasToSchemas({
|
||||
refPointerPrefix: "#/components/schemas/",
|
||||
});
|
||||
|
||||
//Spec creation based on the previously created schemas
|
||||
const spec = generateSpec(storage, schemas);
|
||||
app.get(["/docs/openapi.json", "/docs/swagger.json"], (req, res) => {
|
||||
res.json(spec);
|
||||
});
|
||||
app.use('/docs', express.static(path.join(__dirname, '../static/docs'), { index: "index.html", extensions: ['html'] }));
|
||||
return app;
|
||||
};
|
||||
Reference in New Issue
Block a user