feat:生产环境https协议校验

This commit is contained in:
weiwei committed 2025-08-15 17:29:48 +08:00
1 parent a8c03e3089
commit a472af7625
2 files changed
+22

No files matched your search

+14
View File
@@ -47,7 +47,21 @@ const https = new Request({
},
})
// 生产环境协议安全检查
const validateProductionSecurity = () => {
if (isDevEnv()) return
const apiUrl = import.meta.env.VITE_API_URL
if (apiUrl && !apiUrl.startsWith("https://")) {
uni.showToast({ title: "生产环境安全错误: 必须使用 HTTPS 协议", icon: "error" })
throw new Error("生产环境禁止使用 HTTP 协议")
}
}
https.interceptors.request.use(async (config) => {
// 生产环境协议检查
validateProductionSecurity()
const tokenStorage = uni.getStorageSync(TOKEN_KEY)
const config_header: any = config.header || {}
+8
View File
@@ -9,6 +9,12 @@ import { useRouter } from "./src/sheep"
export default defineConfig(({ mode }) => {
const { NODE_ENV, VITE_APP_DEV_SERVICE, VITE_APP_PROD_SERVICE, VITE_IMAGE_DEV_PATH } = loadEnv(mode, process.cwd(), "")
const baseUrl = NODE_ENV == "development" ? VITE_APP_DEV_SERVICE : VITE_APP_PROD_SERVICE
// 生产环境强制 HTTPS 检查
if (NODE_ENV === "production" && baseUrl && !baseUrl.startsWith("https://")) {
throw new Error("生产环境必须使用 HTTPS 协议!请检查 VITE_APP_PROD_SERVICE 配置")
}
return {
build: {
target: "es6",
@@ -40,6 +46,8 @@ export default defineConfig(({ mode }) => {
ws: true,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ""),
// 生产环境强制 HTTPS 验证
...(NODE_ENV === "production" && { secure: true }),
},
},
},