HTTPS for local development
How to enable HTTPS on localhost with Vite and mkcert

Search for a command to run...
How to enable HTTPS on localhost with Vite and mkcert

No comments yet. Be the first to comment.
A living log of experiments, ideas, and lessons learned while building software. Some things work, some don’t — everything gets documented.
Introduction JavaScript, as a dynamic and ever-evolving programming language, continues to introduce new features and enhancements to cater to the needs of developers. Among its most recent additions is the Object.groupBy method, is a powerful and ve...
Low-code platforms can be excellent for validating an idea. The risk begins when a temporary launch stack becomes permanent infrastructure for a growing product.

A practical, opinionated baseline for securing fresh Debian/Ubuntu VPS servers before deploying real apps.

There are two kinds of developers: those who fear regex, and those who use it like a superpower. The funny part? It’s the same tool — the difference is perspective.Most people think of regex as the thing you use to validate emails, phone numbers, or ...

Why accessibility is everyone’s responsibility

Using HTTPS for local development is no longer optional. Modern browsers require a secure context to enable key features like PWAs, Service Workers, camera access, and WebAuthn. If your local dev server still runs on HTTP, you’re likely missing bugs that only appear in production.
This guide shows how to enable HTTPS on localhost using Vite and mkcert, with a setup that works on desktop and real mobile devices.
Browsers restrict powerful APIs to HTTPS to protect users. These restrictions apply even in local development environments.
You need HTTPS on localhost if your app uses:
Progressive Web Apps (PWA)
Service Workers
Camera or microphone access
WebAuthn / passkeys
Secure cookies and storage APIs
Mobile testing on real devices
While localhost sometimes works without HTTPS, local IP access does not. If you test your app on an iPhone or Android device using your machine’s IP, HTTPS is mandatory.
mkcert is the recommended tool for local HTTPS development because it creates trusted certificates, not self-signed ones. That means:
No browser security warnings
Works across browsers
Ideal for Vite, Next.js, and other dev servers
On macOS, install mkcert using Homebrew:
brew install mkcert
mkcert -install
This creates a local Certificate Authority and adds it to your system trust store.
Generate certificates for localhost and loopback addresses:
mkcert localhost 127.0.0.1 ::1
This creates:
localhost.pem
localhost-key.pem
These files will be used by your Vite dev server to enable HTTPS.
vite.config.ts file:import fs from "fs";
export default {
server: {
host: "::",
port: 8080,
https: {
key: fs.readFileSync("./localhost-key.pem"),
cert: fs.readFileSync("./localhost.pem"),
},
},
};
{
...
"scripts": {
"dev": "next dev --experimental-https --experimental-https-key ./localhost+2-key.pem --experimental-https-cert ./localhost+2.pem",
...
}
This configuration:
Enables HTTPS in Vite
Allows IPv4 and IPv6 access
Matches production-like behavior
Restart the dev server after applying the changes.
To test HTTPS local development on mobile:
Connect your phone to the same Wi-Fi network
Find your computer’s local IP address
Open the app in your phone browser:
https://[your-local-ip]:8080
This setup works on iOS Safari and Chrome for Android without certificate warnings.
PWAs and Service Workers only work over HTTPS (except limited localhost cases). If your PWA behaves differently in production than in development, missing HTTPS is usually the cause.
With this setup, you can:
Install your PWA locally
Debug Service Worker caching
Test offline behavior
Validate mobile-only features early
✅ Trusted HTTPS certificates (mkcert)
✅ No browser warnings
✅ Works on real devices
✅ Matches production security rules
✅ Compatible with Vite and modern frameworks
If you’re building modern web applications, HTTPS on localhost should be your default, not an afterthought.
Using mkcert with Vite gives you:
Production parity
Reliable mobile testing
Fewer deployment surprises
Once you switch to HTTPS local development, you won’t want to go back.