84 lines
2.0 KiB
Markdown
84 lines
2.0 KiB
Markdown
## Step 5: Set Up HTTPS with mkcert (Windows)
|
|
|
|
**1. Install mkcert (if not already installed):**
|
|
```powershell
|
|
choco install mkcert
|
|
```
|
|
|
|
**2. Install local certificate authority:**
|
|
```powershell
|
|
mkcert -install
|
|
```
|
|
|
|
**3. Create certificates directory:**
|
|
```powershell
|
|
mkdir certs
|
|
mkcert -cert-file certs/localhost+2.pem -key-file certs/localhost+2-key.pem localhost 127.0.0.1 ::1
|
|
```
|
|
|
|
This creates:
|
|
• certs/localhost+2.pem (certificate)
|
|
• certs/localhost+2-key.pem (private key)
|
|
|
|
**4. Install Uvicorn (ASGI server with SSL support):**
|
|
|
|
Ensure you are at the project root and venv is activated:
|
|
```powershell
|
|
pip install uvicorn[standard]
|
|
```
|
|
|
|
**5. Update requirements.txt:**
|
|
```powershell
|
|
pip freeze > requirements.txt
|
|
```
|
|
|
|
**6. Create run.bat script (Windows):**
|
|
```batch
|
|
@echo off
|
|
uvicorn backend.asgi:application ^
|
|
--host 127.0.0.1 --port 8000 ^
|
|
--ssl-keyfile ./certs/localhost+2-key.pem ^
|
|
--ssl-certfile ./certs/localhost+2.pem
|
|
```
|
|
|
|
Note: Replace backend with your project name if different.
|
|
|
|
**7. Create VS Code launch configuration (optional):**
|
|
|
|
For debugging in VS Code, create `.vscode/launch.json`:
|
|
|
|
```powershell
|
|
mkdir .vscode -Force
|
|
@"
|
|
{
|
|
"version": "0.2.0",
|
|
"configurations": [
|
|
{
|
|
"name": "Django HTTPS (Uvicorn)",
|
|
"type": "debugpy",
|
|
"request": "launch",
|
|
"module": "uvicorn",
|
|
"args": [
|
|
"backend.asgi:application",
|
|
"--host", "0.0.0.0",
|
|
"--port", "8000",
|
|
"--ssl-keyfile", "./certs/localhost+2-key.pem",
|
|
"--ssl-certfile", "./certs/localhost+2.pem",
|
|
"--reload"
|
|
],
|
|
"django": true,
|
|
"justMyCode": true,
|
|
"python": "`${workspaceFolder}/venv/Scripts/python.exe"
|
|
}
|
|
]
|
|
}
|
|
"@ | Out-File -FilePath .vscode/launch.json -Encoding utf8
|
|
```
|
|
|
|
This allows you to:
|
|
- Run and debug Django with F5 in VS Code
|
|
- Set breakpoints in your Django code
|
|
- Automatic venv activation via the `python` path
|
|
|
|
Note: Replace `backend` with your project name if different. On Windows, the Python path uses `venv/Scripts/python.exe`.
|