Skip to content
This repository has been archived by the owner on Sep 18, 2019. It is now read-only.

How to use Node's tls.createSecureContext with Hapi? #768

Closed
pixelsbysarah opened this issue Jan 30, 2019 · 0 comments
Closed

How to use Node's tls.createSecureContext with Hapi? #768

pixelsbysarah opened this issue Jan 30, 2019 · 0 comments

Comments

@pixelsbysarah
Copy link

Hello! I'm trying to reload our renewed SSL certificates without having to restart the app (Context: Reload certificate files of https.createServer() without restarting node server: nodejs/node#15115).

I'm not sure how to implement tls.createSecureContext() or tls.getSecureContext() when creating a Hapi Server.

Below is what I last tried, but I get an error in my IDE: TS2322: Type 'import("https").Server' is not assignable to type 'import("http".Server'. Property 'maxHeadersCount' is missing in type 'Server'. Is there a different server.options property I should be using?

import { Server } from 'hapi';
import * as Boom from 'boom';
import * as path from 'path'
import * as https from 'https';
import * as fs from 'fs';
import * as tls from 'tls';
import * as Loki from 'lokijs';

// ...other code...
const portNumber: 43210
const certs = tls.createSecureContext({
    key: fs.readFileSync('/path/to/key.pem'),
    cert: fs.readFileSync('/path/to/cert.pem'),
});
const httpsOptions = {
    SNICallback: (serverName, cb) => {
        cb(null, certs);
    }
}

//  ... other code ...

const app = new Server({
    listener: https.createServer(httpsOptions), \\ TS2322 Error occurs here
    port: portNumber,
    routes: { cors: true },
    tls: true
});

Is options.listener the right property to use for createSecureContext() or is there some other property or way to use it?

Thanks in advance for your assistance!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants