我正在构建一个旨在为移动应用程序提供服务的应用程序。除了为客户提供服务外,它还将具有多种后台功能。
我们正在使用swagger,并且我们确实希望能够访问后台端点的 swagger 文档。但是,我们不想公开暴露我们的所有端点。
假设将所有端点公开是一个糟糕的选择,我们正在考虑的一种解决方案是让我们的服务器服务两个端口,然后只向公众公开一个端口。我们创建了一个小型示例存储库,为两个不同端口上的客户端模块和后台模块提供服务。
看起来main.ts像下面这样:
import { NestFactory } from '@nestjs/core';
import { ClientModule } from './modules/client/client.module';
import * as express from 'express';
import * as http from 'http';
import {ExpressAdapter} from '@nestjs/platform-express';
import { BackOfficeModule } from './modules/backoffice/backoffice.module';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
async function bootstrap() {
const clientServer = express();
const clientApp = await NestFactory.create(
ClientModule,
new ExpressAdapter(clientServer),
);
const clientOptions = new DocumentBuilder()
.setTitle('ClientServer')
.setDescription('The client server API …Run Code Online (Sandbox Code Playgroud)