feat(server): add tsoa to generate api swaggers
This commit is contained in:
@@ -4,16 +4,12 @@ import cors from "cors";
|
||||
import compression from "compression";
|
||||
import nocache from "nocache";
|
||||
import path from "path";
|
||||
import expressOasGenerator, {
|
||||
OpenAPIV3,
|
||||
SPEC_OUTPUT_FILE_BEHAVIOR,
|
||||
} from "express-oas-generator";
|
||||
|
||||
dotenv.config({ path: path.resolve(__dirname, "../../../.env") });
|
||||
|
||||
import "./database";
|
||||
import { sequelize } from "@/database/instance";
|
||||
import { createApis } from "./api";
|
||||
import { RegisterTsoaRoutes } from "./middleware/tsoa.middleware";
|
||||
|
||||
const port = process.env.PORT || 3005;
|
||||
|
||||
@@ -26,29 +22,9 @@ app.use(compression());
|
||||
|
||||
app.use(express.static(path.resolve(__dirname, "client")));
|
||||
|
||||
createApis(app);
|
||||
// Register tsoa routes
|
||||
RegisterTsoaRoutes(app);
|
||||
|
||||
expressOasGenerator.handleResponses(app, {
|
||||
specOutputFileBehavior: SPEC_OUTPUT_FILE_BEHAVIOR.RECREATE,
|
||||
swaggerDocumentOptions: {},
|
||||
predefinedSpec: (spec: OpenAPIV3.Document) => {
|
||||
if (spec.info) {
|
||||
spec.info.description = "Egret App Server";
|
||||
}
|
||||
if (spec.paths) {
|
||||
delete spec.paths["/v3/api-docs"];
|
||||
}
|
||||
return spec;
|
||||
},
|
||||
});
|
||||
|
||||
expressOasGenerator.handleRequests();
|
||||
|
||||
app.get("/v3/api-docs", async (req, res) => {
|
||||
expressOasGenerator.getSpecV3((err, doc) => {
|
||||
res.status(200).json(doc);
|
||||
});
|
||||
});
|
||||
|
||||
const host = "0.0.0.0";
|
||||
app.listen(Number(port), host, async () => {
|
||||
|
||||
Reference in New Issue
Block a user