Scert/frontend/vite.config.js
xuans 76d2321ed4
Some checks are pending
Build and Release / Build Release Package (tar.gz, amd64, linux) (push) Waiting to run
Build and Release / Build Release Package (tar.gz, arm64, linux) (push) Waiting to run
Build and Release / Build Release Package (zip, amd64, windows) (push) Waiting to run
fix(frontend): 优化开发代理请求头以支持初始化同源校验
2026-10-20 11:27:46 +08:00

46 lines
1.1 KiB
JavaScript

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [vue()],
publicDir: 'logo',
build: {
sourcemap: false,
},
server: (() => {
const apiTarget = process.env.SCERT_API_TARGET || 'https://127.0.0.1:5200';
const targetUrl = new URL(apiTarget);
const apiProxy = {
target: apiTarget,
changeOrigin: true,
secure: false,
headers: {
Origin: targetUrl.origin,
'Sec-Fetch-Site': 'same-origin',
},
};
return {
host: process.env.SCERT_DEV_HOST || '127.0.0.1',
port: Number(process.env.SCERT_DEV_PORT || 5173),
proxy: {
'/api': apiProxy,
'/healthz': apiProxy,
'/reset': {
...apiProxy,
bypass(request) {
if (
request.method === 'GET' &&
request.headers.accept &&
request.headers.accept.includes('text/html')
) {
return '/index.html';
}
return undefined;
},
},
},
};
})(),
})