Skip to content

Commit

Permalink
feat: HTTPS deployment for universal server (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhhyi committed Feb 20, 2020
1 parent 671aad3 commit 90e6440
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 8 deletions.
2 changes: 2 additions & 0 deletions dist/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
!/*.sh
!/healthcheck.js
!/robots.txt
!/server.crt
!/server.key
23 changes: 23 additions & 0 deletions dist/server.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-----BEGIN CERTIFICATE-----
MIIDxDCCAqygAwIBAgIJAJYvMbbAjzehMA0GCSqGSIb3DQEBCwUAMIGNMQswCQYD
VQQGEwJERTELMAkGA1UECAwCVEgxDTALBgNVBAcMBEplbmExEjAQBgNVBAoMCUlu
dGVyc2hvcDEUMBIGA1UECwwLRW5naW5lZXJpbmcxJDAiBgkqhkiG9w0BCQEWFXN1
cHBvcnRAaW50ZXJzaG9wLmNvbTESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTIwMDEx
NDA4NDExOVoXDTIxMDExMzA4NDExOVowgY0xCzAJBgNVBAYTAkRFMQswCQYDVQQI
DAJUSDENMAsGA1UEBwwESmVuYTESMBAGA1UECgwJSW50ZXJzaG9wMRQwEgYDVQQL
DAtFbmdpbmVlcmluZzEkMCIGCSqGSIb3DQEJARYVc3VwcG9ydEBpbnRlcnNob3Au
Y29tMRIwEAYDVQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
ggEKAoIBAQDRXcHHCh2XNXdsH3zy8OQK+T6H6K29HoRus0wzv8Hp8jSbdOrF2RuH
9EeEbdrZe+EXhiuLGg76xvxD1dLwANA5fgVIo0/nrIR7Hj1m3fAFiKGBPNSCF0UX
P9ljWPH0U6WhHVcb+EinQdISQHObT0/OLefPZDQg5ymlZV/+fvlBV0hFkBvpSO30
541EjUm3BubwvyciREOo1PKxnhAyUAZd7SjdM5+ORjfCX3GutTLIv7+XKUABHJ9f
AzJ8uig60hpcsx2cceNlTQ92uEReT5qAadDwLDwVNl5DZ2jhUvjhVlZZWHtW045D
YxCbxCjnanbn+0cydsgSxv9zvMxwB+x1AgMBAAGjJTAjMCEGA1UdEQQaMBiCCyou
bG9jYWxob3N0gglsb2NhbGhvc3QwDQYJKoZIhvcNAQELBQADggEBAA55lAtHrxzS
095HRl/5PQ/M1zUjgOUvLlR5WKKxdzU/nbc/n8wuZqfPL4CHD7s8EJ442yvw+WgP
mqaiXlPBqDCQkrDgHwWnjyT7ndrl7N52bKue14i32nTlsLn/pf+FOMoDnimghQeL
DqFzcLkHacgaxIHt5A0xy3cU/64gMeiL52V+PrgQCD4heeimIjtxGAB4c97GB7TR
FIkk2a4iUzHs5NEv60hKm+Ksgw48wI/jHrCfcxvXJ07f5Qt57IjZkoNmCEq6NX0V
5vvneRQjdFiprE/uiFusdSYGV1Hz2E9HrY0x/LLseS+CGWTBUlWZkOZTpdsnaqDh
DTNpH0moNzI=
-----END CERTIFICATE-----
28 changes: 28 additions & 0 deletions dist/server.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDRXcHHCh2XNXds
H3zy8OQK+T6H6K29HoRus0wzv8Hp8jSbdOrF2RuH9EeEbdrZe+EXhiuLGg76xvxD
1dLwANA5fgVIo0/nrIR7Hj1m3fAFiKGBPNSCF0UXP9ljWPH0U6WhHVcb+EinQdIS
QHObT0/OLefPZDQg5ymlZV/+fvlBV0hFkBvpSO30541EjUm3BubwvyciREOo1PKx
nhAyUAZd7SjdM5+ORjfCX3GutTLIv7+XKUABHJ9fAzJ8uig60hpcsx2cceNlTQ92
uEReT5qAadDwLDwVNl5DZ2jhUvjhVlZZWHtW045DYxCbxCjnanbn+0cydsgSxv9z
vMxwB+x1AgMBAAECggEAWZmFR3g1x7NzA0vKfnHHNkcKks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qRs32qM3erskcRwzvxmegbtTByvP59kTmwiGHkquotmN5ifqJHe
2let3V6NCMEZ0qU6LKG6GTBaBZhHuHzuyPBhDW/6i1qZZxRNV73HteluQgXWkmVQ
UZoOi8uheodOmR4V9Mf9MREUmg==
-----END PRIVATE KEY-----
26 changes: 18 additions & 8 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,21 @@ app.get('*', (req: express.Request, res: express.Response) => {
);
});

// Start up the Node server
app.listen(PORT, () => {
console.log(`Node Express server listening on http://localhost:${PORT}`);
const icmBaseUrl = process.env.ICM_BASE_URL;
if (icmBaseUrl) {
console.log('ICM_BASE_URL is', icmBaseUrl);
}
});
if (process.env.SSL) {
const https = require('https');
const privateKey = fs.readFileSync(join(DIST_FOLDER, 'server.key'), 'utf8');
const certificate = fs.readFileSync(join(DIST_FOLDER, 'server.crt'), 'utf8');
const credentials = { key: privateKey, cert: certificate };

https.createServer(credentials, app).listen(PORT);

console.log(`Node Express server listening on https://${require('os').hostname()}:${PORT}`);
} else {
const http = require('http');

http.createServer(app).listen(PORT);

console.log(`Node Express server listening on http://${require('os').hostname()}:${PORT}`);
}

console.log('ICM_BASE_URL is', ICM_BASE_URL);

0 comments on commit 90e6440

Please sign in to comment.