• 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

  • 相关阅读:
    从淘宝数据结构来看电子商务中商品属性设计
    YY淘宝商品数据库设计
    ElasticSearch-聚合bucket学习
    ElasticSearch-聚合bucket
    Elasticsearch(9) --- 聚合查询(Bucket聚合)
    Elasticsearch-多字段搜索(Multifield Search)和提高精确度
    五、设备管理与文件系统
    六、YUM仓库
    四、查找命令
    二、用户权限
  • 原文地址:https://www.cnblogs.com/ajanuw/p/12665083.html
Copyright © 2020-2023  润新知