fix: widget SDK无法加载的三个问题
1. Vite proxy缺少/widget转发 — SDK调用/widget/init等API时被SPA fallback 拦截返回HTML。添加/widget proxy并bypass HTML页面请求到/widget.html。 2. ParseWebWidgetConfig类型不匹配 — seed数据中channel_config JSON的 "continuity_via_email":""是空字符串,但Go结构体字段是bool, json.Unmarshal报UnmarshalTypeError导致整个config解析失败, findInboxByWebsiteToken跳过该inbox。容忍类型不匹配错误, 只对JSON语法错误返回error。 3. dev模式SDK bundle不可用 — /sdk/js/sdk.js在Vite dev模式下无构建产物, 被SPA fallback返回HTML。构建SDK后放入public/供dev server静态提供。
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -122,6 +122,17 @@ export default defineConfig({
|
||||
target: process.env.VITE_API_HOST || 'http://127.0.0.1:3000',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/widget': {
|
||||
target: process.env.VITE_API_HOST || 'http://127.0.0.1:3000',
|
||||
changeOrigin: true,
|
||||
// Let Vite handle the /widget standalone HTML page (rewrite to /widget.html),
|
||||
// proxy everything else (API calls: /widget/init, /widget/conversations, etc.)
|
||||
bypass(req) {
|
||||
if (req.headers.accept?.includes('text/html')) {
|
||||
return '/widget.html';
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
build: {
|
||||
|
||||
Reference in New Issue
Block a user