使用同一个项目 Adonisjs 启动 http 和 https
Start both http and https with the same project Adonisjs
我想在我的 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 路由的最优化方法是完全创建一个实例,这样我们就不必将 https 路由与不会在 http 请求中使用的 http 路由一起加载。
我想在我的 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 路由的最优化方法是完全创建一个实例,这样我们就不必将 https 路由与不会在 http 请求中使用的 http 路由一起加载。