How to enable HTTPS is AdonisJS 5 ? #1742
-
I was using this code in express to enable https:
I have the certificate and the private key stored on the server in a separate file , i made the cert and the key using this command:
Now how do i use them to enable ssl ? thanks for help and support |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Inside import { createServer } from "https";
import { Ignitor } from "@adonisjs/core/build/src/Ignitor";
new Ignitor(__dirname).httpServer().start((handle) => {
return createServer(
{
key: "",
cert: "",
},
handle
);
}); |
Beta Was this translation helpful? Give feedback.
-
In my case, I want to use // server.ts
import { Ignitor } from '@adonisjs/core/build/standalone';
import Env from '@ioc:Adonis/Core/Env';
import { readFileSync } from 'fs';
import { createServer as createHttpServer } from 'http';
import { createServer as createHttpsServer } from 'https';
import 'reflect-metadata';
import sourceMapSupport from 'source-map-support';
sourceMapSupport.install({ handleUncaughtExceptions: false });
new Ignitor(__dirname).httpServer().start((handle) => {
if (Env.get('SSL_KEY')) {
return createHttpsServer(
{
key: readFileSync(Env.get('SSL_KEY')),
cert: readFileSync(Env.get('SSL_CERT')),
},
handle
);
} else {
return createHttpServer(handle);
}
}); Throw errors:
|
Beta Was this translation helpful? Give feedback.
Inside
server.ts
, you can pass a callback to thestart
method to return a custom Node.js server instance. Checkout the following example.