https://github.com/elado/fake-https-cert
https://github.com/elado/fake-https-cert
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/elado/fake-https-cert
- Owner: elado
- Created: 2021-03-12T23:17:43.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-03-16T19:41:12.000Z (almost 5 years ago)
- Last Synced: 2025-03-03T02:39:18.956Z (10 months ago)
- Language: JavaScript
- Size: 256 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# `fake-https-cert`
> Create fake SSL certificates for `https://localhost` to work.
> Shamelessly stolen from `webpack-dev-server`.
**Before using this, be sure to look at [mkcert](https://github.com/FiloSottile/mkcert)**
## Install
```sh
npm i -D fake-https-cert
yarn add --dev fake-https-cert
```
## Usage
```js
const { createServer } = require("https");
const fakeHttpsCert = require("fake-https-cert");
const fakeCert = getCertificate(console);
const httpsOptions = {
key: fakeCert,
cert: fakeCert,
};
createServer(httpsOptions, (req, res) => {
const urlObj = parse(req.url, true);
handle(req, res, urlObj);
}).listen(3000, () => {
console.log("> Server started on https://localhost:3000");
});
```
### Usage with Next.js
Create a `server.js`, run with `node server.js` instead of `yarn dev`.
```js
const { createServer } = require("https");
const next = require("next");
const fakeHttpsCert = require("fake-https-cert");
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();
const fakeCert = fakeHttpsCert(console);
const httpsOptions = {
key: fakeCert,
cert: fakeCert,
};
app.prepare().then(() => {
createServer(httpsOptions, (req, res) => {
const url = 'https://' + req.headers.host + req.url;
const urlObj = new URL(url);
handle(req, res, urlObj);
}).listen(3000, () => {
console.log("> Server started on https://localhost:3000");
});
});
```
### Browser Support
Welp, browsers don't really like it, but if you enable this certificate manually, they'll forgive you.
