uechi.io/source/_posts/2020/secure-dev-server.md

23 lines
753 B
Markdown
Raw Permalink Normal View History

2020-02-07 12:07:43 +09:00
---
title: Securing Local Dev Server
date: 2020-02-07 00:00:00 +0900
---
2021-01-21 21:45:05 +09:00
2020-02-07 12:07:43 +09:00
Sometimes you want to interact with a local webserver with https support because of some browser APIs that are only available in an https environment.
You can easily create a self-signed TLS cert for development purposes with [`mkcert`](https://github.com/FiloSottile/mkcert).
2020-02-07 12:37:31 +09:00
```bash
2020-02-07 12:07:43 +09:00
brew install mkcert
mkcert -install # Install the local CA in the OS keychain
```
After installing `mkcert` and generating system-wide local CA cert, you can create a certificate for each project.
2020-02-07 12:37:31 +09:00
```bash
2020-02-07 12:07:43 +09:00
cd awesome-website
mkcert localhost # this will generate ./localhost.pem and ./localhost-key.pem
npm install -g serve
serve --ssl-cert ./localhost.pem --ssl-key ./localhost-key.pem
2021-01-21 21:45:05 +09:00
```