Deploy: DocfyUiModule vs standalone
Serveer het vanuit dezelfde NestJS-app die de API aanbiedt, of als statische bundel op elke statische host.
Installatie
npm install docfy-uiDit pakket levert een vooraf gebouwde statische bundel (dist/): er is geen server-side code te installeren op een Node-backend. Gebruik je nestjs-docfy, dan wrapt DocfyUiModule.setup() dit al voor je; serveer anders de map dist/ met een willekeurige statische file server.
Via DocfyUiModule.setup()
De eenvoudigste setup als je backend NestJS is: laat nestjs-docfy dit pakket voor je mounten.
import { NestFactory } from "@nestjs/core";
import { SwaggerModule, DocumentBuilder } from "@nestjs/swagger";
import { DocfyUiModule } from "nestjs-docfy";
const app = await NestFactory.create(AppModule);
DocfyUiModule.setup("/docs", app); // before SwaggerModule.setup
const document = SwaggerModule.createDocument(app, new DocumentBuilder().build());
SwaggerModule.setup("api", app, document); // exposes /api-json, which docfy-ui fetches by default
await app.listen(3000);Ga naar /docs: geen extra configuratie nodig.
Standalone (statisch)
Zonder nestjs-docfy bouw en serveer je de statische assets zelf en wijs je ze naar een willekeurig OpenAPI-document:
npm run build # in this package, or use the prebuilt dist/ from npmServeer dist/ met een willekeurige statische host (NestJS' ServeStaticModule, Nginx, S3 + CloudFront, enz.), naast of vóór de API die de spec aanbiedt.
Verwijzen naar een remote spec
Staat de spec op een andere origin, gebruik dan de ?spec=<url>-override (zie Configuratie).