Pārlūkot izejas kodu

fix: stabilize beta application submission

chenyu 2 mēneši atpakaļ
vecāks
revīzija
904c49c1ba
2 mainītis faili ar 22 papildinājumiem un 18 dzēšanām
  1. 3 2
      frontend/src/pages/public/BetaApplyPage.tsx
  2. 19 16
      frontend/vite.config.js

+ 3 - 2
frontend/src/pages/public/BetaApplyPage.tsx

@@ -17,9 +17,10 @@ export function BetaApplyPage() {
   const handleSubmit = async (event: FormEvent<HTMLFormElement>) => {
     event.preventDefault()
     if (submitting) return
+    const form = event.currentTarget
     setSubmitting(true)
     setError('')
-    const data = new FormData(event.currentTarget)
+    const data = new FormData(form)
     try {
       await submitBetaApplication({
         name: String(data.get('name') || ''),
@@ -35,7 +36,7 @@ export function BetaApplyPage() {
         painPoint: String(data.get('painPoint') || '') || undefined,
       })
       setSubmitted(true)
-      event.currentTarget.reset()
+      form.reset()
     } catch (submitError) {
       setError(submitError instanceof Error ? submitError.message : pageCopy.error)
     } finally {

+ 19 - 16
frontend/vite.config.js

@@ -1,22 +1,25 @@
-import { defineConfig } from 'vite'
+import { defineConfig, loadEnv } from 'vite'
 import react from '@vitejs/plugin-react'
 
 // https://vite.dev/config/
-export default defineConfig({
-  plugins: [react()],
-  server: {
-    proxy: {
-      // 开发环境下把 /api 同源代理到后端,避免浏览器 CORS 预检
-      // 可选:把 client.ts 的 API_BASE 设为相对 '/api/v1' 即走此同源代理
-      '/api': {
-        target: 'http://127.0.0.1:3000',
-        changeOrigin: true,
+export default defineConfig(({ mode }) => {
+  const env = loadEnv(mode, process.cwd(), '')
+
+  return {
+    plugins: [react()],
+    server: {
+      proxy: {
+        // 开发环境下把 /api 同源代理到后端,避免浏览器 CORS 预检
+        '/api': {
+          target: env.VITE_DEV_API_TARGET || 'http://127.0.0.1:3000',
+          changeOrigin: true,
+        },
       },
     },
-  },
-  test: {
-    environment: 'jsdom',
-    setupFiles: './src/test/setup.ts',
-    exclude: ['**/.worktrees/**', '**/node_modules/**', '**/dist/**'],
-  },
+    test: {
+      environment: 'jsdom',
+      setupFiles: './src/test/setup.ts',
+      exclude: ['**/.worktrees/**', '**/node_modules/**', '**/dist/**'],
+    },
+  }
 })