zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Vue-router 报NavigationDuplicated的可能解决方案
    go 数据类型转换
    在vscode 之中使用 GO MOD
    javascript格式化
    Mac node-sass 安装失败“v8::String::Utf8Value”
    Django 使用gunicorn 和 supervisord部署
    关于windows上的账号(权限)切换
    python中的global关键字
    暂时性的小总结
    windwos 安装下kafka的安装使用
  • 原文地址:https://www.cnblogs.com/ajanuw/p/12665083.html
Copyright © 2011-2022 走看看