initialize redoc

This commit is contained in:
Fran Jurmanović
2023-10-03 00:08:14 +02:00
parent 224c2f32c7
commit fb98df8f98
7 changed files with 226 additions and 25 deletions

View File

@@ -3,9 +3,10 @@ import { Chat } from "@common";
import { Controller } from "@core";
import { ClientController } from "@controllers";
import express from "express";
import { config } from "@constants";
import basicAuth from "express-basic-auth";
import { APP_VERSION, config } from "@constants";
import bodyParser from "body-parser";
import redoc from "redoc-express";
import path from "path";
const client: Client = new Client();
const chat: Chat = new Chat(client);
@@ -13,16 +14,47 @@ const app = express();
app.use(bodyParser.json());
app.use(
basicAuth({
users: {
admin: config.PASSWORD,
app.get("/docs/swagger.json", (req, res) => {
res.sendFile("swagger.json", { root: path.join(__dirname, "..") });
});
app.get(
"/docs",
redoc({
title: "API Docs",
specUrl: "/docs/swagger.json",
nonce: "",
redocOptions: {
theme: {
colors: {
primary: {
main: "#6EC5AB",
},
},
typography: {
fontFamily: `"museo-sans", 'Helvetica Neue', Helvetica, Arial, sans-serif`,
fontSize: "15px",
lineHeight: "1.5",
code: {
code: "#87E8C7",
backgroundColor: "#4D4D4E",
},
},
menu: {
backgroundColor: "#ffffff",
},
},
},
})
);
const controllers = new Controller([new ClientController(client, app)]);
app.get("version", (_, res) => {
res.send(APP_VERSION);
});
const controllers = new Controller(app, [new ClientController(client)]);
controllers.register();
chat.register(config.TOKEN || "");
app.listen(config.PORT);
app.listen(config.PORT, () =>
console.log(`Legica bot API listening on port ${config.PORT}!`)
);