-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: mkcert 패키지 install 스크립트 작성 * feat: next https custom server 작성
- Loading branch information
Showing
4 changed files
with
77 additions
and
4 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 @@ | ||
#!/bin/bash | ||
|
||
readonly DEFAULT_HOSTS="localhost 127.0.0.1 ::1" | ||
readonly hostname=$1 | ||
|
||
readonly mkcert_intalled=$(which mkcert) | ||
|
||
readonly cert_dir="$PWD/.certificates" | ||
readonly key_path="$cert_dir/localhost-key.pem" | ||
readonly cert_path="$cert_dir/localhost.pem" | ||
|
||
if [ -z $mkcert_intalled ];then | ||
echo "💬 Downloading mkcert package...\n" | ||
brew install mkcert | ||
fi | ||
|
||
mkdir $cert_dir | ||
|
||
echo "💬 Attempting to generate self-signed certificate...\n" | ||
|
||
if [ "$hostname" != "" ];then | ||
mkcert -install -key-file $key_path -cert-file $cert_path $DEFAULT_HOSTS $hostname | ||
else | ||
mkcert -install -key-file $key_path -cert-file $cert_path $DEFAULT_HOSTS | ||
fi | ||
|
||
echo "🚀 CA Root certificate created!" | ||
echo "🚀 Certificates created in ${cert_dir}" |
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,43 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const fs = require('fs'); | ||
const https = require('https'); | ||
const { parse } = require('url'); | ||
const next = require('next'); | ||
|
||
const dev = process.env.NODE_ENV !== 'production'; | ||
const hostname = process.argv[2]; | ||
const port = 3000; | ||
|
||
// when using middleware `hostname` and `port` must be provided below | ||
const app = next({ dev, hostname, port }); | ||
const handle = app.getRequestHandler(); | ||
|
||
const SELF_CERTIFICATES_PATH = { | ||
key: './.certificates/localhost-key.pem', | ||
cert: './.certificates/localhost.pem', | ||
}; | ||
|
||
const option = { | ||
key: fs.readFileSync(SELF_CERTIFICATES_PATH.key), | ||
cert: fs.readFileSync(SELF_CERTIFICATES_PATH.cert), | ||
}; | ||
|
||
app.prepare().then(() => { | ||
https | ||
.createServer(option, async (req, res) => { | ||
try { | ||
// Be sure to pass `true` as the second argument to `url.parse`. | ||
// This tells it to parse the query portion of the URL. | ||
const parsedUrl = parse(req.url, true); | ||
handle(req, res, parsedUrl); | ||
} catch (err) { | ||
console.error('Error occurred handling', req.url, err); | ||
res.statusCode = 500; | ||
res.end('internal server error'); | ||
} | ||
}) | ||
.listen(port, error => { | ||
if (error) throw error; | ||
console.log(`> Ready on https://${hostname}:${port}`); | ||
}); | ||
}); |
File renamed without changes.