Dear Leonie,
-I wanted to ask you something very special...
-Will you be my Valentine?
- - -diff --git a/.vscode/settings.json b/.vscode/settings.json index 6f3a291..f673a71 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,3 @@ { - "liveServer.settings.port": 5501 + "liveServer.settings.port": 5502 } \ No newline at end of file diff --git a/hihi/answer.txt b/hihi/answer.txt new file mode 100644 index 0000000..dcd7a5d --- /dev/null +++ b/hihi/answer.txt @@ -0,0 +1 @@ +Yes diff --git a/hihi/backend.js b/hihi/backend.js index ea5abb0..0cd8d1a 100644 --- a/hihi/backend.js +++ b/hihi/backend.js @@ -1,20 +1,27 @@ const express = require('express'); -const fs = require('fs'); +const cors = require('cors'); +const writeFileAtomic = require('write-file-atomic'); const app = express(); +const port = 3000; +app.use(cors()); app.use(express.json()); app.post('/save_answer', (req, res) => { const answer = req.body.answer; - fs.writeFile('answer.txt', answer, err => { + console.log(`Received answer: ${answer}`); // Print the received answer + + writeFileAtomic('answer.txt', `${answer}\n`, { encoding: 'utf8', mode: 0o600 }, function (err) { if (err) { - console.error(err); - res.status(500).send('An error occurred while writing the answer to a file.'); + console.error(`Error writing to file: ${err}`); // Print the error + res.status(500).json({ message: 'Error writing to file' }); } else { - console.log('Answer saved to file.'); - res.status(200).send('Answer saved to file.'); + console.log('Saved!'); + res.status(200).json({ message: 'Answer saved' }); } }); }); -app.listen(3000, () => console.log('Server listening on port 3000.')); \ No newline at end of file +app.listen(port, () => { + console.log(`Server listening at http://localhost:${port}`); +}); \ No newline at end of file diff --git a/hihi/cat.gif b/hihi/cat.gif new file mode 100644 index 0000000..c2777fa Binary files /dev/null and b/hihi/cat.gif differ diff --git a/hihi/index.html b/hihi/index.html index 76f7aea..a797ff3 100644 --- a/hihi/index.html +++ b/hihi/index.html @@ -1,27 +1,24 @@
-