mirror of
https://github.com/DerTyp7/notes-react.git
synced 2025-10-29 20:42:09 +01:00
saving
This commit is contained in:
@@ -5,6 +5,12 @@ const sqlite3 = require('sqlite3');
|
||||
const db = new sqlite3.Database("database.db")
|
||||
const port = process.env.PORT || 5000;
|
||||
|
||||
// body parser
|
||||
const bodyParser = require('body-parser');
|
||||
app.use(bodyParser.json());
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
|
||||
|
||||
app.use(function(req, res, next) {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
res.header("Access-Control-Allow-Methods","POST","GET")
|
||||
@@ -39,4 +45,15 @@ app.get('/ideas', (req, res) => {
|
||||
res.json(rows);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
app.post('/idea/update/:id', (req, res) => {
|
||||
db.run(`UPDATE ideas SET title = '${req.body.title}', content = '${req.body.content}' WHERE id = ${req.params.id}`, (err) => {
|
||||
if (err) {
|
||||
res.send({title: "Error", content: "Error updating idea"});
|
||||
}else{
|
||||
res.send({title: "Success", content: "Idea updated"});
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user