forked from Yara724/api
61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
import { NestFactory } from "@nestjs/core";
|
|
import { NestExpressApplication } from "@nestjs/platform-express";
|
|
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
|
|
import * as basicAuth from "express-basic-auth";
|
|
import { AppModule } from "./app.module";
|
|
|
|
async function bootstrap() {
|
|
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
|
|
cors: true,
|
|
});
|
|
|
|
app.enableCors();
|
|
|
|
app.enableCors({
|
|
origin: "*",
|
|
methods: "GET, PUT, POST, DELETE, PATCH, OPTIONS",
|
|
allowedHeaders: "Content-Type, Authorization",
|
|
});
|
|
|
|
app.use(
|
|
["/docs", "/docs-json", "/swagger"],
|
|
basicAuth({
|
|
challenge: true,
|
|
users: {
|
|
[process.env.SWAGGER_USER]: process.env.SWAGGER_PASSWORD,
|
|
},
|
|
}),
|
|
);
|
|
|
|
const config = new DocumentBuilder()
|
|
.setTitle("yara724-backend")
|
|
.setVersion("1.0.0")
|
|
.addServer(process.env.URL)
|
|
.addServer(process.env.BASE_URL + "/api")
|
|
.addServer("http://192.168.20.249:9001")
|
|
.addServer("http://192.168.20.170:9001")
|
|
.addServer("http://localhost:9001")
|
|
.addBearerAuth()
|
|
.build();
|
|
const docs = SwaggerModule.createDocument(app, config);
|
|
SwaggerModule.setup("/docs", app, docs, {
|
|
swaggerOptions: {
|
|
persistAuthorization: true,
|
|
docExpansion: "none",
|
|
tagsSorter: (a: string, b: string) => {
|
|
const priority: Record<string, number> = {
|
|
user: 0,
|
|
actor: 1,
|
|
};
|
|
const pa = priority[a] ?? 100;
|
|
const pb = priority[b] ?? 100;
|
|
if (pa !== pb) return pa - pb;
|
|
return a.localeCompare(b);
|
|
},
|
|
},
|
|
});
|
|
await app.listen(process.env.PORT);
|
|
}
|
|
|
|
bootstrap();
|