Nestjs 设置https
只是用https
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| import * as fs from 'fs'; import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; const httpsOptions = { key: fs.readFileSync('/Users/afacode/localhost_ssl/blog.afacode.top.key'), cert: fs.readFileSync('/Users/afacode/localhost_ssl/blog.afacode.top.crt'), }; async function bootstrap() { const app = await NestFactory.create(AppModule, { httpsOptions, }); app.enableCors(); console.log(`https://blog.afacode.top:3000/`); await app.listen(3000); } bootstrap();
|
http和https
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| import * as fs from 'fs'; import * as http from "http"; import * as https from "https"; import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; import * as express from 'express'; import { ExpressAdapter } from '@nestjs/platform-express'; const httpsOptions = { key: fs.readFileSync('/Users/afacode/localhost_ssl/blog.afacode.top.key'), cert: fs.readFileSync('/Users/afacode/localhost_ssl/blog.afacode.top.crt'), }; async function bootstrap() { const server = express(); const app = await NestFactory.create( AppModule, new ExpressAdapter(server) ); app.setGlobalPrefix('api'); app.enableCors(); await app.init(); console.log(`http://blog.afacode.top:3000`); console.log(`https://blog.afacode.top`); http.createServer(server).listen(3000); https.createServer(httpsOptions, server).listen(443); } bootstrap();
|
如有问题可联系 Email:afacode@outlook.com 或 微信:afacode