Första incheckningen. Protyp för PWA för att skapa todos
This commit is contained in:
33
server.js
Normal file
33
server.js
Normal 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}`);
|
||||
});
|
||||
Reference in New Issue
Block a user