1.10.5.6. fejezet, SSL

Mintakód HTTPS szerverre

require("dotenv").config();
import express, { Router } from 'express';
import fs from "fs";
import https from "https";
import bodyParser from 'body-parser';
import routeTenant from './routes/routeTenant';
 
const app = express();
 
const ssl = {
    key: fs.readFileSync('server.key'),
    cert: fs.readFileSync('server.crt'),
    rejectUnauthorized: false,
};
 
const port = process.env.PORT || 8443
 
const jsonParser = bodyParser.json();
app.use(jsonParser);
 
app.use('/api/v2/tenant', routeTenant);
 
https.createServer(ssl, app).listen(port, () => {
    console.log(`Ready on https://localhost:${port}`);
});

SSL cert kezelésről röviden itt