This commit is contained in:
parent
19c596a6d4
commit
ffa7378480
@ -6,6 +6,8 @@ import {router} from "@/router";
|
||||
const http = axios.create({
|
||||
baseURL: import.meta.env.VITE_APP_URL, //接口统一域名
|
||||
timeout: 60000,
|
||||
// 初始化授权和登录会话都依赖服务端 Cookie;开发代理或反向代理跨源时也必须携带 Cookie。
|
||||
withCredentials: true,
|
||||
xsrfCookieName: 'smail_csrf',
|
||||
xsrfHeaderName: 'X-CSRF-Token',
|
||||
withXSRFToken: true, //设置超时
|
||||
|
||||
@ -1,12 +1,16 @@
|
||||
import { fileURLToPath, URL } from 'node:url'
|
||||
import { defineConfig } from 'vite'
|
||||
import { defineConfig, loadEnv } from 'vite'
|
||||
import AutoImport from 'unplugin-auto-import/vite'
|
||||
import Components from 'unplugin-vue-components/vite'
|
||||
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
export default defineConfig(({ mode }) => {
|
||||
const env = loadEnv(mode, process.cwd(), '')
|
||||
const backendUrl = (env.VITE_DEV_BACKEND_URL || 'http://127.0.0.1:9001').replace(/\/$/, '')
|
||||
|
||||
return {
|
||||
plugins: [
|
||||
vue(),
|
||||
AutoImport({
|
||||
@ -24,8 +28,15 @@ export default defineConfig({
|
||||
server: {
|
||||
cors: true,
|
||||
proxy: {
|
||||
"/api": "http://127.0.0.1/",
|
||||
"/attachments":"http://127.0.0.1/"
|
||||
"/api": {
|
||||
target: backendUrl,
|
||||
changeOrigin: false
|
||||
},
|
||||
"/attachments": {
|
||||
target: backendUrl,
|
||||
changeOrigin: false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@ -204,4 +204,7 @@ func Setup(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// 初始化接口必须始终返回统一 JSON,避免未知步骤被当成空响应,
|
||||
// 进而让前端误判请求已完成并进入错误页面。
|
||||
response.NewErrorResponse(response.ParamsError, "不支持的初始化操作", "").FPrint(w)
|
||||
}
|
||||
|
||||
34
server/controllers/setup_contract_test.go
Normal file
34
server/controllers/setup_contract_test.go
Normal file
@ -0,0 +1,34 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
appcontext "git.pcux.cn/xuans/Smail/utils/context"
|
||||
)
|
||||
|
||||
func TestSetupReturnsJSONForUnsupportedOperation(t *testing.T) {
|
||||
request := httptest.NewRequest("POST", "/api/v1/setup", strings.NewReader(`{"step":"unknown","action":"unknown"}`))
|
||||
response := httptest.NewRecorder()
|
||||
|
||||
Setup(&appcontext.Context{}, response, request)
|
||||
|
||||
if response.Code != 200 {
|
||||
t.Fatalf("setup status = %d, want 200", response.Code)
|
||||
}
|
||||
if contentType := response.Header().Get("Content-Type"); !strings.HasPrefix(contentType, "application/json") {
|
||||
t.Fatalf("setup content type = %q, want JSON", contentType)
|
||||
}
|
||||
var payload struct {
|
||||
ErrorNo int `json:"errorNo"`
|
||||
ErrorMsg string `json:"errorMsg"`
|
||||
}
|
||||
if err := json.Unmarshal(response.Body.Bytes(), &payload); err != nil {
|
||||
t.Fatalf("decode setup response: %v", err)
|
||||
}
|
||||
if payload.ErrorNo != 100 || payload.ErrorMsg != "不支持的初始化操作" {
|
||||
t.Fatalf("unexpected setup response: %+v", payload)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user