topfans/frontend/vite.config.js
Lenticular Studio Agent af7908e72e feat: 接入微达API中转站,重构镭射卡生图流程
- 替换中转站从 xbcl.link 到 weda.cc
- prompt 模板改为镭射卡全图生成(去掉 6 层合成/抠图依赖)
- 4 路并发调用 + 原图展示 = 5 张 variant
- 前端提示词中译英支持
- 全局 Vue errorHandler
- WebSocket 鉴权失败跳登录
- 删除已弃用的 laserCompositor 微服务

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-23 22:43:49 +08:00

91 lines
2.7 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 https from 'node:https'
import { createRequire } from 'node:module'
// @dcloudio/vite-plugin-uni v3 alpha 的 dist 是 CJS
// 且 __esModule 标志为非枚举Node 的 CJS-to-ESM 互操作
// 不会把它当 TS 编译产物,于是 `import uni from ...` 拿到的
// 是整个 module.exports 对象而不是函数,调用就报
// "uni is not a function"。用 createRequire 直走 CJS 拿 default。
const require = createRequire(import.meta.url)
const uni = require('@dcloudio/vite-plugin-uni').default
/** 与 upload-signature 返回的 OSS 虚拟域名一致;换桶时请同步 */
const OSS_DEV_HOST = 'top-fans-test.oss-cn-shanghai.aliyuncs.com'
/**
* 部分环境下 Vite 内置 server.proxy 的 rewrite 对 POST 未生效OSS 仍收到路径
* /dev-oss-proxy从而 405ResourceType: Object。此处用中间件固定转发到桶根 POST /。
*/
function ossDevPostProxyPlugin() {
return {
name: 'oss-dev-post-proxy',
configureServer(server) {
server.middlewares.use((req, res, next) => {
const raw = req.url || ''
if (!raw.startsWith('/dev-oss-proxy')) {
return next()
}
if (req.method === 'OPTIONS') {
res.statusCode = 204
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS')
res.setHeader(
'Access-Control-Allow-Headers',
String(req.headers['access-control-request-headers'] || '*')
)
res.end()
return
}
if (req.method !== 'POST') {
res.statusCode = 405
res.setHeader('Content-Type', 'text/plain; charset=utf-8')
res.end('OSS dev proxy only allows POST')
return
}
const hop = new Set([
'connection',
'keep-alive',
'proxy-authenticate',
'proxy-authorization',
'te',
'trailers',
'transfer-encoding',
'upgrade'
])
/** @type {import('node:http').OutgoingHttpHeaders} */
const headers = {}
for (const [k, v] of Object.entries(req.headers)) {
if (v === undefined || hop.has(k.toLowerCase())) continue
headers[k] = v
}
headers.host = OSS_DEV_HOST
const proxyReq = https.request(
{
hostname: OSS_DEV_HOST,
port: 443,
method: 'POST',
path: '/',
headers
},
(proxyRes) => {
res.writeHead(proxyRes.statusCode || 502, proxyRes.headers)
proxyRes.pipe(res)
}
)
proxyReq.on('error', (err) => {
if (!res.headersSent) {
res.statusCode = 502
res.setHeader('Content-Type', 'text/plain; charset=utf-8')
}
res.end(err.message)
})
req.pipe(proxyReq)
})
}
}
}
export default defineConfig({
plugins: [ossDevPostProxyPlugin(), uni()]
})