fix: add HTTPS support for microphone access on remote servers#11
Merged
Conversation
- Add getUserMedia availability check with clear error message - Add Nginx self-signed cert setup script (scripts/setup-https.sh) for enabling HTTPS on IP-only servers where mediaDevices is undefined
There was a problem hiding this comment.
Pull request overview
This PR improves microphone/voice feature reliability when the app is accessed from remote (non-localhost) servers by adding an explicit getUserMedia availability guard in the web client and providing a helper script to enable HTTPS via Nginx with a self-signed certificate.
Changes:
- Add a preflight check for
navigator.mediaDevices.getUserMediawith a clear error message before starting recording. - Add
scripts/setup-https.shto generate a self-signed cert and write an Nginx HTTPS reverse-proxy config for IP-based access.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
vocata-web/src/utils/aiChat.ts |
Adds runtime guard to fail fast with a clear message when getUserMedia is unavailable (typically non-HTTPS contexts). |
scripts/setup-https.sh |
Adds an automation script to generate certs and configure Nginx for HTTPS access to enable microphone permissions remotely. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+7
to
+34
| SERVER_IP="86.53.161.33" | ||
| SSL_DIR="/etc/nginx/ssl" | ||
| NGINX_CONF="/etc/nginx/sites-available/vocata-https" | ||
|
|
||
| echo "=== 1. 生成自签 SSL 证书 ===" | ||
| mkdir -p "$SSL_DIR" | ||
|
|
||
| # 生成含 IP SAN 的证书(现代浏览器要求 SAN,不认纯 CN) | ||
| openssl req -x509 -nodes -days 365 -newkey rsa:2048 \ | ||
| -keyout "$SSL_DIR/vocata.key" \ | ||
| -out "$SSL_DIR/vocata.crt" \ | ||
| -subj "/C=CN/ST=Beijing/O=VocaTa/CN=$SERVER_IP" \ | ||
| -addext "subjectAltName=IP:$SERVER_IP" | ||
|
|
||
| echo "证书已生成: $SSL_DIR/vocata.crt" | ||
|
|
||
| echo "" | ||
| echo "=== 2. 写入 Nginx 配置 ===" | ||
| cat > "$NGINX_CONF" <<'NGINX' | ||
| # VocaTa HTTPS 反向代理 | ||
| # 前端: https://86.53.161.33 → localhost:3000 | ||
| # 后端: https://86.53.161.33/api → localhost:9009 | ||
| # WebSocket: wss://86.53.161.33/ws → localhost:9009 | ||
|
|
||
| server { | ||
| listen 443 ssl; | ||
| server_name 86.53.161.33; | ||
|
|
Comment on lines
+8
to
+12
| SSL_DIR="/etc/nginx/ssl" | ||
| NGINX_CONF="/etc/nginx/sites-available/vocata-https" | ||
|
|
||
| echo "=== 1. 生成自签 SSL 证书 ===" | ||
| mkdir -p "$SSL_DIR" |
| -out "$SSL_DIR/vocata.crt" \ | ||
| -subj "/C=CN/ST=Beijing/O=VocaTa/CN=$SERVER_IP" \ | ||
| -addext "subjectAltName=IP:$SERVER_IP" | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 变更内容
✅ 测试验证
PR 提交规范提醒: