-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: auto generate ssl certificates
- Loading branch information
Raymond Ottun
committed
Nov 11, 2021
1 parent
fa21879
commit fe9afe3
Showing
8 changed files
with
74 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[ | ||
{ | ||
"name": "Successful todo", | ||
"id": "first_behavior", | ||
"request": { | ||
"path": "/todo/[0-9]+", | ||
"method": "(GET|POST|DELETE|PUT)" | ||
}, | ||
"response": { | ||
"body": { | ||
"id": 2, | ||
"text": "The todo body" | ||
} | ||
} | ||
}, | ||
{ | ||
"name": "Failed todo", | ||
"id": "last_behavior", | ||
"request": { | ||
"path": "/customer", | ||
"method": "(GET|POST|DELETE|PUT)" | ||
}, | ||
"response": { | ||
"statusCode": 500, | ||
"body": "Server blew up" | ||
} | ||
} | ||
] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,33 @@ | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import * as devcert from 'devcert'; | ||
|
||
const TLS_CERT_NAME = 'cert.pem'; | ||
const TLS_KEY_NAME = 'key.pem'; | ||
const keyFile = path.join(process.cwd(), 'ssl', TLS_KEY_NAME); | ||
const certFile = path.join(process.cwd(), 'ssl', TLS_CERT_NAME); | ||
|
||
export const loadSSLCerts = () => { | ||
return { | ||
cert: fs.readFileSync(certFile), | ||
key: fs.readFileSync(keyFile), | ||
}; | ||
}; | ||
|
||
export const isTLSEnabled = () => { | ||
const isSSLExisting = () => { | ||
if (process.env.NODE_ENV === 'test') { | ||
return false; | ||
} | ||
return fs.existsSync(keyFile) && fs.existsSync(certFile); | ||
}; | ||
|
||
const generateSSL = async ({ domains }) => { | ||
const { key, cert } = await devcert.certificateFor(['localhost', ...domains]); | ||
|
||
fs.mkdirSync(path.join(process.cwd(), 'ssl')); | ||
fs.writeFileSync(keyFile, key); | ||
fs.writeFileSync(certFile, cert); | ||
}; | ||
|
||
export const loadSSLCerts = async ({ domains }) => { | ||
if (!isSSLExisting()) { | ||
await generateSSL({ domains }); | ||
} | ||
return Promise.resolve({ | ||
cert: fs.readFileSync(certFile), | ||
key: fs.readFileSync(keyFile), | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters