Skip to content

Commit

Permalink
19
Browse files Browse the repository at this point in the history
  • Loading branch information
collinlucke committed Nov 28, 2024
1 parent ff3b77c commit 6438b4b
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,22 @@ const httpServer = http.createServer(app);
httpServer.listen(5050, () => {
console.log(`🚀 HTTP server listening on port 5050`);
});
if (process.env.NODE_ENV === 'production') {
// Serve HTTPS on port 443

const readCert = (envVar, filePath) => {
if (process.env[envVar]) {
return process.env[envVar].replace(/\\n/g, '\n');
}
return fs.readFileSync(path.join(__dirname, filePath), 'utf8');
};
// Serve HTTPS on port 443
const readCert = (envVar, filePath) => {
if (process.env[envVar]) {
return process.env[envVar].replace(/\\n/g, '\n');
}
return fs.readFileSync(path.join(__dirname, filePath), 'utf8');
};

const httpsOptions = {
key: readCert('SSL_PRIVATE_KEY', '../keyfile.key'),
cert: readCert('SSL_CERT', '../certfile.cer'),
ca: [readCert('SSL_CERT_INTERMEDIATE', '../intermediate.cer')]
};
const httpsOptions = {
key: readCert('SSL_PRIVATE_KEY', '../keyfile.key'),
cert: readCert('SSL_CERT', '../certfile.cer'),
ca: [readCert('SSL_CERT_INTERMEDIATE', '../intermediate.cer')]
};

const httpsServer = https.createServer(httpsOptions, app);
httpsServer.listen(443, () => {
console.log('Server is running on https://localhost:443');
});
}
const httpsServer = https.createServer(httpsOptions, app);
httpsServer.listen(443, () => {
console.log('Server is running on https://localhost:443');
});

0 comments on commit 6438b4b

Please sign in to comment.