Files
EchoChat/frontend/vite.config.js
2026-05-14 20:40:04 +08:00

42 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import basicSsl from '@vitejs/plugin-basic-ssl'
// https://vitejs.dev/config/
//
// HTTPS 说明WebRTC 必需):
// 浏览器仅在 secure context 下开放 navigator.mediaDevicesgetUserMedia 等 API
// 手机通过局域网 IP http://192.168.x.x:5173 访问时 mediaDevices 会是 undefined。
// 因此 dev 默认开启自签 HTTPS同时把 /api 与 /ws 走同源代理转回后端 HTTP
// 这样浏览器只与 vite HTTPS 通信,前端代码无需关心后端是否 TLS。
//
// 代理目标由环境变量 VITE_DEV_BACKEND 控制,默认 http://localhost:8085
// 若后端跑在其他主机/端口(如 docker 主机)可自行覆盖。
const BACKEND = process.env.VITE_DEV_BACKEND || 'http://yl.z64.cn:8085'
const BACKEND_WS = BACKEND.replace(/^http/, 'ws')
export default defineConfig({
plugins: [
uni(),
basicSsl(),
],
base: '/echoChat-frontend/',
server: {
host: '0.0.0.0',
https: true,
proxy: {
'/api': {
target: BACKEND,
changeOrigin: true,
secure: false,
},
'/ws': {
target: BACKEND_WS,
changeOrigin: true,
ws: true,
secure: false,
},
},
},
})