• Nestjs 设置https


    只是用https

    import * as fs from 'fs';
    
    import { NestFactory } from '@nestjs/core';
    import { AppModule } from './app.module';
    
    const httpsOptions = {
      key: fs.readFileSync('D:/localhost_ssl/dev.ajanuw.com.key'),
      cert: fs.readFileSync('D:/localhost_ssl/dev.ajanuw.com.crt'),
    };
    
    async function bootstrap() {
      const app = await NestFactory.create(AppModule, {
        httpsOptions,
      });
      app.enableCors();
      // 我配置了hosts文件,让dev.ajanuw.com指向127.0.0.1
      console.log(`https://dev.ajanuw.com:3000/`);
      await app.listen(3000);
    }
    bootstrap();
    

    http和https

    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('D:/localhost_ssl/dev.ajanuw.com.key'),
      cert: fs.readFileSync('D:/localhost_ssl/dev.ajanuw.com.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://dev.ajanuw.com:3000`);
      console.log(`https://dev.ajanuw.com`);
      http.createServer(server).listen(3000);
      https.createServer(httpsOptions, server).listen(443);
    }
    bootstrap();
    

    如果要访问http:http://dev.ajanuw.com:3000,https:https://dev.ajanuw.com

  • 相关阅读:
    常见的几种性能测试指标及计算公式
    性能测试分析
    性能测试的流程
    性能测试的基本知识
    Python的深拷贝、浅拷贝
    Http基础知识
    求List<int>中相等且连续的偶数的索引
    unity资源打包之后配置的生成
    unity在资源打包的时候,关于 hash 计算的简单总结
    C#中string.Join的用法
  • 原文地址:https://www.cnblogs.com/ajanuw/p/12665083.html
Copyright © 2020-2023  润新知