feat(widget): Widget 配置、loader 与右下角悬浮入口
生成可嵌入站点的 loader 与悬浮按钮,支持展开收起和移动端;附独立宿主测试页。
This commit is contained in:
1 parent
e24d3e2a65
commit
5d0a48505a
57 files changed
+32086
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import express from "express";
|
||||
import { fileURLToPath } from "url";
|
||||
import { dirname, join } from "path";
|
||||
import cors from "cors";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
const app = express();
|
||||
const port = process.env.PORT || 3000;
|
||||
|
||||
// This server only hosts the test pages. The widget loader is NOT kept here — the
|
||||
// pages load it from the frontend origin (vite dev server locally, the dashboard
|
||||
// origin in production), exactly like the embed snippet the dashboard generates.
|
||||
// A copy in this folder would go stale and silently test an old widget.
|
||||
const FRONTEND_ORIGIN = process.env.FRONTEND_ORIGIN || "http://localhost:5173";
|
||||
|
||||
// Enable CORS for the widget script
|
||||
app.use(cors());
|
||||
|
||||
// Serve static files
|
||||
app.use(express.static(__dirname));
|
||||
|
||||
// Serve index.html
|
||||
app.get("/", (req, res) => {
|
||||
res.sendFile(join(__dirname, "index.html"));
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Test server running at http://localhost:${port}`);
|
||||
console.log(`UI options gallery: http://localhost:${port}/ui-options.html`);
|
||||
console.log(`Widget loader from: ${FRONTEND_ORIGIN}/webclient/chattermate.min.js`);
|
||||
console.log(`(rebuild it after loader changes: cd ../frontend && npm run build:webclient:prod)`);
|
||||
});
|
||||
Reference in new issue
Block a user