4.0 KiB
Setting Up SSL for Local Development
Installing Chocolatey (Windows Only)
What is Chocolatey?
Chocolatey is a package manager for Windows, making it easy to install and manage software packages via the command line.
Steps to Install Chocolatey:
-
Open PowerShell as Administrator:
- Press
Windows + Xand select Windows PowerShell (Admin) from the menu.
- Press
-
Run the Following Command to Install Chocolatey:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) -
Verify the Installation: Once the installation is complete, you can verify Chocolatey is installed by running the following command:
choco --versionIf Chocolatey is installed correctly, it will output the current version number.
Common Chocolatey Commands
-
Install a package:
choco install <package_name> -
Uninstall a package:
choco uninstall <package_name> -
Upgrade all installed packages:
choco upgrade all
Additional Notes
- Chocolatey is required for installing
mkcertand other software dependencies. - Make sure to always run PowerShell as Administrator when using Chocolatey to install or manage packages.
Setting Up SSL for Local Development
To ensure that your local development environment runs with SSL, follow these steps to generate a locally trusted SSL certificate using mkcert:
Requirements
Steps
-
Install
mkcert:-
Install
mkcertusing Chocolatey on Windows (or use an appropriate package manager for other OS). -
For Windows users, open PowerShell as Administrator and run:
choco install mkcert -
For macOS users, run:
brew install mkcert
-
-
Install the Local Certificate Authority (CA): After installing
mkcert, run the following command to install the local CA:mkcert -installThis will set up a trusted local CA to issue certificates.
-
Generate SSL Certificates: In your project root (or a preferred directory), generate the SSL certificate and key for
localhost:mkcert localhostThis will generate two files:
localhost.pem(the certificate)localhost-key.pem(the private key)
-
Update the
vite.config.js: Ensure your project is set up to use the generated certificate. Yourvite.config.jsshould contain the following lines to enable SSL for the development server:import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; import fs from 'fs'; import path from 'path'; export default defineConfig({ plugins: [vue()], server: { https: { key: fs.readFileSync(path.resolve(__dirname, 'path_to_your_key/localhost-key.pem')), cert: fs.readFileSync(path.resolve(__dirname, 'path_to_your_cert/localhost.pem')), }, host: 'localhost', }, });Replace
path_to_your_keyandpath_to_your_certwith the location of your generated certificate and key files. -
Start the Development Server: Run the development server with SSL by using:
npm run dev -
Access the Application: Open your browser and navigate to
https://localhost:3000(or the port your Vite server is running on).
Additional Notes
- If you encounter any issues related to SSL, ensure that the local CA is properly installed by running
mkcert -installagain. - Each developer should follow these steps to generate their own trusted SSL certificate. Avoid committing the generated
.pemand.keyfiles to version control for security reasons.