UNPKG

textdotjs

Version:

text.js

27 lines (20 loc) 846 B
const express = require('express'); const fs = require('fs'); const path = require('path'); const app = express(); app.use(express.json({limit: '10mb'})); // Serve static files from the 'public' directory app.use(express.static(path.join(__dirname, 'public'))); app.post('/save', (req, res) => { const filename = req.body.filename || 'index.html'; if (!filename.match(/^[a-z0-9_\-\.]+$/i)) { return res.status(400).send('Invalid filename'); } // Save to the 'public' directory const filePath = path.join(__dirname, 'public', filename); fs.writeFile(filePath, req.body.html, err => { if (err) return res.status(500).send('Error saving file'); res.send('File saved'); }); }); app.listen(3000, () => console.log('Text.js server running on http://localhost:3000'));