Skip to content

Commit

Permalink
Merge pull request #5 from familab/mjh/feature/explorer
Browse files Browse the repository at this point in the history
Added Swagger API Explorer for Auth Server
  • Loading branch information
bkwrm95 authored Feb 21, 2024
2 parents c646c22 + d4c9981 commit cf1c874
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 7 deletions.
3 changes: 3 additions & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"googleapis-common": "^7.0.1",
"reflect-metadata": "^0.1.13",
"routing-controllers": "^0.10.4",
"routing-controllers-openapi": "^4.0.0",
"swagger-ui-express": "^5.0.0",
"typedi": "^0.10.0",
"winston": "^3.11.0"
},
Expand All @@ -31,6 +33,7 @@
"@types/node": "^20.8.10",
"@types/sinon": "^17.0.3",
"@types/supertest": "^2.0.15",
"@types/swagger-ui-express": "^4.1.6",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"chai": "^4.3.10",
Expand Down
26 changes: 21 additions & 5 deletions api/src/router.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
import { useContainer, useExpressServer } from "routing-controllers";
import { Container } from "typedi";
import { Router } from "express";
import { getMetadataArgsStorage, RoutingControllersOptions, useContainer, useExpressServer } from "routing-controllers";
import { routingControllersToSpec } from "routing-controllers-openapi";
import { serve, setup } from "swagger-ui-express";
import { Container } from "typedi";
import "reflect-metadata";

import { AccessController } from "./controllers/access-controller.js";
import "./logger.js";

export const router = Router()
// Declare router
export const router = Router();

useContainer(Container);
useExpressServer(router, {
// Define configuration for RoutingControllers
const options: RoutingControllersOptions = {
routePrefix: "/api",
controllers: [
AccessController,
]
};

// Setup routing-controllers server
useContainer(Container);
useExpressServer(router, options);

// Setup Swagger explorer
const swaggerSpec = routingControllersToSpec(getMetadataArgsStorage(), options, {
info: {
title: "FamiLAB Access Control",
version: "4"
}
});
router.use('/explorer', serve, setup(swaggerSpec));
3 changes: 2 additions & 1 deletion api/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import express from "express";
import { Container } from "typedi";
import { Logger } from "winston";

import { env } from "./env.js";
import { router } from "./router.js";

Expand All @@ -12,5 +13,5 @@ app.use(router);
// Start the server
const port = env.serverPort;
app.listen(port, () => {
logger.info(`Server started at http://localhost:${port}.`);
logger.info(`Server started. Explore API at http://localhost:${port}/explorer.`);
});
69 changes: 68 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cf1c874

Please sign in to comment.