feat: update server

This commit is contained in:
2026-04-21 18:00:54 +07:00
parent d8f18c0d9d
commit 99bc387244
2 changed files with 345 additions and 1 deletions
+29 -1
View File
@@ -1,3 +1,6 @@
const fs = require('fs');
const path = require('path');
module.exports = {
server: {
baseDir: "output",
@@ -13,5 +16,30 @@ module.exports = {
port: 3300,
open: false,
notify: false,
ui: false
ui: false,
middleware: [
{
route: "/api/save-editor",
handle: function (req, res, next) {
if (req.method !== 'POST') return next();
let body = '';
req.on('data', chunk => body += chunk);
req.on('end', () => {
try {
const data = JSON.parse(body);
const name = path.basename(data.file || 'unknown', '.html');
const dir = path.join(__dirname, 'output', 'editor-saves');
fs.mkdirSync(dir, { recursive: true });
const savePath = path.join(dir, name + '.json');
fs.writeFileSync(savePath, JSON.stringify(data, null, 2));
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ ok: true, path: savePath }));
} catch (e) {
res.writeHead(400, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ error: e.message }));
}
});
}
}
]
};