feat: update server
This commit is contained in:
+29
-1
@@ -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 }));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user