unjs / listhen

👂 Elegant HTTP Listener
Other
455 stars 30 forks source link

feat: persist generated https certificates #132

Open danielwaltz opened 1 year ago

danielwaltz commented 1 year ago

Describe the feature

When using self-signed generated certificates for local development, every time you restart listhen (or in my case restart the nuxt dev server), a new certificate is generated and your browser's "Your connection is not private" page must be explicitly bypassed.

As a small optimization, it would be very nice if the generated certificates were (maybe optionally) persisted to disk so that you only need to manually bypass the browser's insecure warning page once (or each time a new certificate is generated). This is similar to how @vitejs/plugin-basic-ssl works by saving the cert inside of a hidden temp dir in your project's node_modules directory (./node_modules/.vite/basic-ssl).

I could see listhen doing something similar by persisting the certs at ./node_modules/.listhen/certs.

I'm not sure if this has security implications or may be unreliable depending on the runtime environment, so if this is impractical and/or unadvisable I completely understand. Thanks!

Additional information

pi0 commented 1 year ago

Thanks for the idea! The default behavior of not persisting was kinda intentional to make sure warn users everytime about this and avoid possible local cert leaking problems but at least via an opt-in flag/option i think we can implement this feature 💯