Cleaned up the loaders

ref #11
This commit is contained in:
Nicolai Ort 2020-12-05 19:09:08 +01:00
parent a3a809bb40
commit f58a715c45
4 changed files with 19 additions and 4 deletions

View File

@ -1,5 +1,8 @@
import { createConnection } from "typeorm";
/**
* Loader for the database that creates the database connection and initializes the database tabels.
*/
export default async () => {
const connection = await createConnection();
connection.synchronize();

View File

@ -1,7 +1,9 @@
import { Application } from "express";
import bodyParser from 'body-parser';
import cors from 'cors';
/**
* Loader for express related configurations.
* Currently only enables the proxy trust.
*/
export default async (app: Application) => {
app.enable('trust proxy');
return app;

View File

@ -1,8 +1,11 @@
import { Application } from "express";
import databaseLoader from "./database";
import expressLoader from "./express";
import openapiLoader from "./openapi";
import databaseLoader from "./database";
import { Application } from "express";
/**
* Index Loader that executes the other loaders in the right order.
*/
export default async (app: Application) => {
await databaseLoader();
await openapiLoader(app);

View File

@ -4,11 +4,16 @@ import { getMetadataArgsStorage } from "routing-controllers";
import { routingControllersToSpec } from "routing-controllers-openapi";
import * as swaggerUiExpress from "swagger-ui-express";
/**
* Loader for everything openapi related - from creating the schema to serving it via a static route.
*/
export default async (app: Application) => {
const storage = getMetadataArgsStorage();
const schemas = validationMetadatasToSchemas({
refPointerPrefix: "#/components/schemas/",
});
//Spec creation based on the previously created schemas
const spec = routingControllersToSpec(
storage,
{
@ -32,6 +37,8 @@ export default async (app: Application) => {
},
}
);
//Options for swaggerUiExpress
const options = {
explorer: true,
};