Files
openmotion/studio/vite.dev.config.ts
open-design-crew[bot] 74a3d1e79d
Some checks failed
Motion standalone checks / Template library policy (push) Has been cancelled
Motion standalone checks / Maintainability report (push) Has been cancelled
Motion standalone checks / Source checks (push) Has been cancelled
Motion standalone checks / Workspace reliability (macos-15) (push) Has been cancelled
Motion standalone checks / Workspace reliability (windows-2025) (push) Has been cancelled
Motion standalone checks / Studio regression (1/2) (push) Has been cancelled
Motion standalone checks / Studio regression (2/2) (push) Has been cancelled
Motion standalone checks / Distribution browser regression (push) Has been cancelled
Motion standalone checks / Distribution regression (push) Has been cancelled
Motion standalone checks / standalone (push) Has been cancelled
DSH integration / Optional DSH plugin (push) Has been cancelled
Motion release controls / controls (push) Has been cancelled
Update README star history / refresh (push) Has been cancelled
Revert "feat(super-agent): add Super Agent workspace, Artifact Viewer, unified resource hub, and Agent Runtimes (#808)" (#877)
Reverts commit 216e12abfe on main while keeping #808 (and follow-up #848) intact on the next branch for continued local/desktop Super Agent development.

Preserves subsequent main commits (#844, #847, #849, #851, #854, #856) outside the reverted #808 surface and restores the pre-#808 /mcp routing expectation in tests/server.test.ts.

Co-authored-by: 罗高 <luogao@users.noreply.github.com>
2026-11-23 17:53:30 +08:00

56 lines
2.2 KiB
TypeScript

import { defineConfig, mergeConfig } from 'vite';
import studioConfig from './vite.config';
import { isReservedBackendPath } from '../shared/spa-routes.ts';
export default mergeConfig(studioConfig, defineConfig({
plugins: [{
name: 'openmotion-studio-dev-backend',
apply: 'serve',
configureServer(server) {
server.middlewares.use((req, res, next) => {
const pathname = new URL(req.url || '/', 'http://localhost').pathname;
// Never allow Vite's SPA HTML fallback to swallow reserved backend or MCP endpoints.
if (pathname === '/mcp' || pathname.startsWith('/mcp/')) {
res.statusCode = 404;
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({ error: 'Not found' }));
return;
}
if (isReservedBackendPath(pathname) && pathname.startsWith('/.well-known')) {
res.statusCode = 404;
res.end('Not found');
return;
}
next();
});
},
// Static analysis imports this file without starting a development server.
config() {
const backend = process.env.OPENMOTION_STUDIO_BACKEND;
if (!backend) throw new Error('Set OPENMOTION_STUDIO_BACKEND to the previewUrl printed by npm start.');
const target = new URL(backend);
if (target.protocol !== 'http:' || !['127.0.0.1', 'localhost', '[::1]'].includes(target.hostname)
|| !target.port || target.pathname !== '/' || target.username || target.password || target.search || target.hash) {
throw new Error('OPENMOTION_STUDIO_BACKEND must be an HTTP loopback origin with a port.');
}
// Preserve the browser Host so Studio can check it against Origin on writes.
// ws: game rooms use a WebSocket on /motion-api/games/:id/rooms/:room.
const backendProxy = { target: target.origin, changeOrigin: false, ws: true };
return {
server: {
host: '127.0.0.1',
proxy: {
'^/(?:api|motion-api|design-api)/': backendProxy,
'^/__hyperframes_config$': backendProxy,
'^/connect/': backendProxy,
'/guide-assets/': backendProxy,
'/web/catalog/': backendProxy,
},
},
};
},
}],
}));