initial commit
This commit is contained in:
55
packages/server/src/index.ts
Normal file
55
packages/server/src/index.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import dotenv from "dotenv";
|
||||
import express from "express";
|
||||
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 { createApis } from "./api";
|
||||
|
||||
const port = process.env.PORT || 3005;
|
||||
|
||||
const app = express();
|
||||
app.set("etag", false);
|
||||
app.use(nocache());
|
||||
app.use(cors());
|
||||
app.use(express.json({ limit: "100mb" }));
|
||||
app.use(compression());
|
||||
|
||||
app.use(express.static(path.resolve(__dirname, "client")));
|
||||
|
||||
createApis(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, () => {
|
||||
console.log(`[server]: Server is running at http://${host}:${port}`);
|
||||
});
|
||||
Reference in New Issue
Block a user