Första incheckningen. Protyp för PWA för att skapa todos

This commit is contained in:
2025-01-23 16:51:16 +01:00
parent 1edf21dc50
commit 47dd4c8332
6 changed files with 200 additions and 0 deletions

33
server.js Normal file
View File

@@ -0,0 +1,33 @@
const express = require('express');
const bodyParser = require('body-parser');
const fs = require('fs');
const path = require('path');
const app = express();
const port = 3044;
app.use(bodyParser.json());
app.use(express.static('public'));
// Endpoint to receive task data and append to file
app.post('/add-task', (req, res) => {
const { subject, description, deadline } = req.body;
const orgFormattedData = `
* TODO ${subject}
${description}
SCHEDULED: <${deadline}>
`;
const filePath = path.join(__dirname, 'tasks.org');
fs.appendFile(filePath, orgFormattedData, (err) => {
if (err) {
return res.status(500).send('Error writing to file.');
}
res.send({ message: 'Task added successfully!' });
});
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});