ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## HTTPS 和多服务器 ### HTTPS 为了创建使用 `HTTPS` 协议的应用程序,在传递给`NestFactory`的`create()`方法中设置`httpsOptions`属性: ```typescript const httpsOptions = { key: fs.readFileSync('./secrets/private-key.pem'), cert: fs.readFileSync('./secrets/public-certificate.pem'), }; const app = await NestFactory.create(ApplicationModule, { httpsOptions, }); await app.listen(3000); ``` 如果使用`FastifyAdapter`,则创建应用如下: ```typescript const app = await NestFactory.create<NestFastifyApplication>( ApplicationModule, new FastifyAdapter({ https: httpsOptions }), ); ``` ### 多个同步服务器 下列方法展示了如何使用Nest应用同时监视多个端口(例如,在非HTTPS端口和HTTPS端口)。 ```typescript const httpsOptions = { key: fs.readFileSync('./secrets/private-key.pem'), cert: fs.readFileSync('./secrets/public-certificate.pem'), }; const server = express(); const app = await NestFactory.create( ApplicationModule, new ExpressAdapter(server), ); await app.init(); http.createServer(server).listen(3000); https.createServer(httpsOptions, server).listen(443); ``` > `ExpressAdapter` 需要从 `@nestjs/platform-express` 包导入。`http`和`https`包是原生的Node.js包。 > `GraphQL Subscriptions` 中该方法无法工作。