node.js - 使用同一个项目 Adonisjs 同时启动 http 和 https
问题描述
我希望在我的 adonisjs 项目中同时运行 HTTP 和 HTTPS。现在我的 server.ts 看起来像这样(运行 https):
import 'reflect-metadata'
import sourceMapSupport from 'source-map-support'
import { Ignitor } from '@adonisjs/core/build/standalone'
import { createServer } from "https";
import { readFileSync } from 'fs';
import { join } from 'path';
sourceMapSupport.install({ handleUncaughtExceptions: false })
const privateKey = readFileSync(join(__dirname + '/sslCert/server.pem'), 'utf8');
const certificate = readFileSync(join(__dirname + '/sslCert/server.cert'), 'utf8');
new Ignitor(__dirname).httpServer().start((handle) => {
return createServer(
{
key: privateKey,
cert: certificate,
},
handle
);
});
例如,我希望 https 服务器在 3333 端口上运行,http 服务器在 4444 端口上运行。
解决方案
我发现可以使用相同的应用程序创建一个 http 实例,但在我的情况下,我只想要特定路由的 http 和其他路由的 https。因此,拥有 http 路由的最优化方式是完全创建一个实例,这样我们就不必在不会在 http 请求中使用的 http 路由旁边加载 https 路由。
推荐阅读
- python - 如何创建用于更改数据框名称的循环
- javascript - 根据 Javascript 中现有对象数组的值创建一个数组
- ios - 从另一个类 Swift 更新视图控制器的 UI
- arm - 使用 stm32 发送一条短信后 sim808 冻结
- java - 从 HashMap 获取以添加到 ArrayList 是否通过引用将其存储在 ArrayList 中?
- javascript - 在 JavaScript 中将所有键合并到具有相同 ID 的单个对象中
- flutter - 如何使用 Dart 从 Webview 中按类名获取图像 url
- firebase - 通过 Firebase Functions 将图像下载到用户本地计算机
- gmail - 如何过滤来自以下地址的垃圾邮件:“from@<
>.com”? - arrays - 谷歌表格匹配/索引查询