Fix: Add assets route handler to serve static files from plugin

This commit is contained in:
mmabdalla 2025-12-29 01:40:26 +02:00
parent fc8534168f
commit 77a2d60157

View file

@ -78,12 +78,22 @@ app.get('/editor', serveEditor);
app.use('/api/pages', createPagesRouter());
app.get('/preview/:id', previewPage);
// Placeholder route handlers
// Serve static assets (Vite build outputs)
app.use('/assets', express.static(path.join(__dirname, 'dist', 'assets')));
// Route handlers
async function serveEditor(req, res) {
const indexPath = path.join(__dirname, 'dist', 'frontend', 'index.html');
res.sendFile(indexPath);
}
async function serveAssets(req, res) {
// Extract filepath parameter (everything after /assets/)
const filepath = req.params.filepath || req.path.replace('/assets/', '');
const assetPath = path.join(__dirname, 'dist', 'assets', filepath);
res.sendFile(assetPath);
}
async function previewPage(req, res) {
try {
const pageId = req.params.id;