mirror of
https://github.com/DerTyp7/notes-react.git
synced 2025-10-29 12:32:11 +01:00
init
This commit is contained in:
BIN
express_backend/database.db
Normal file
BIN
express_backend/database.db
Normal file
Binary file not shown.
1909
express_backend/package-lock.json
generated
Normal file
1909
express_backend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
15
express_backend/package.json
Normal file
15
express_backend/package.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "notes",
|
||||
"version": "1.0.0",
|
||||
"description": "A notes-app",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"express": "^4.17.3",
|
||||
"sqlite3": "^4.2.0"
|
||||
}
|
||||
}
|
||||
42
express_backend/server.js
Normal file
42
express_backend/server.js
Normal file
@@ -0,0 +1,42 @@
|
||||
/* Express Backend for my React Notes App */
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const sqlite3 = require('sqlite3');
|
||||
const db = new sqlite3.Database("database.db")
|
||||
const port = process.env.PORT || 5000;
|
||||
|
||||
app.use(function(req, res, next) {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
res.header("Access-Control-Allow-Methods","POST","GET")
|
||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type,authorization,Accept");
|
||||
|
||||
res.header('Access-Control-Allow-Credentials', 'true');
|
||||
next();
|
||||
});
|
||||
|
||||
app.listen(port, () => console.log(`Listening on port ${port}`));
|
||||
|
||||
app.get('/idea/:id', (req, res) => {
|
||||
|
||||
db.all(`SELECT * FROM ideas WHERE id = ${req.params.id}`, (err, rows) => {
|
||||
if (err) {
|
||||
res.send({title: "Error", content: "Error fetching idea"});
|
||||
}else{
|
||||
if(rows.length > 0){
|
||||
res.json(rows[0]);
|
||||
}else{
|
||||
res.send({title: "Error", content: "Idea not found"});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/ideas', (req, res) => {
|
||||
db.all(`SELECT * FROM ideas`, (err, rows) => {
|
||||
if (err) {
|
||||
res.send({title: "Error", content: "Error fetching ideas"});
|
||||
}else{
|
||||
res.json(rows);
|
||||
}
|
||||
});
|
||||
});
|
||||
0
express_backend/sqlHandler.js
Normal file
0
express_backend/sqlHandler.js
Normal file
Reference in New Issue
Block a user