add server nodejs express

This commit is contained in:
user 2024-02-17 00:26:29 +01:00
parent db3fa29d79
commit c68485e41c
10 changed files with 2111 additions and 7 deletions

2
.gitignore vendored
View file

@ -1,5 +1,5 @@
/.phpunit.cache
/node_modules
/**/node_modules
/public/build
/public/hot
/public/storage

View file

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View file

Before

Width:  |  Height:  |  Size: 106 KiB

After

Width:  |  Height:  |  Size: 106 KiB

View file

@ -25,7 +25,8 @@ function loadMap() {
.then(data => {
L.geoJSON(data, {
onEachFeature: function (feature, layer) {
layer.bindPopup('<h2>' + feature.properties.Nome + '</h2><p>' + feature.properties.Descrizione + '</p><img src="' + feature.properties.Foto + '" alt="Photo" style="width:200px;height:auto;">');
layer.bindPopup('<h2>' +
feature.properties.Nome + '</h2><p>' + feature.properties.Descrizione + '</p><img src="' + feature.properties.Foto + '" alt="Photo" style="width:200px;height:auto;">');
}
}).addTo(map);
});

2057
ruscoapp/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

16
ruscoapp/package.json Normal file
View file

@ -0,0 +1,16 @@
{
"name": "ruscoapp",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.2",
"sqlite3": "^5.1.7"
}
}

View file

@ -6,7 +6,7 @@
"properties": {
"Nome": "Televisore",
"Descrizione": "estitcamente messo bene",
"Foto": "foto/tv.jph"
"Foto": "foto/tv.jpg"
},
"geometry": {
"type": "Point",

BIN
ruscoapp/ruscodb Normal file

Binary file not shown.

View file

@ -1,5 +1,7 @@
const express = require('express');
const sqlite3 = require('sqlite3').verbose();
const path = require('path')
const bcrypt = require('crypto');
const app = express();
const port = 3000;
@ -12,10 +14,15 @@ db.serialize(() => {
db.run("CREATE TABLE items (id INTEGER PRIMARY KEY, name TEXT, description TEXT, image_url TEXT, latitude REAL, longitude REAL)");
});
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
})
// Insert a new item into the database
app.get('/add-item', (req, res) => {
app.get('/addRuschi', (req, res) => {
const { name, description, image_url, latitude, longitude } = req.query;
db.run("INSERT INTO items (name, description, image_url, latitude, longitude) VALUES (?, ?, ?, ?, ?)", [name, description, image_url, latitude, longitude], function(err) {
db.run("INSERT INTO ruschi (type, nome, descrizione, foto, lat, lng) VALUES (?, ?, ?, ?, ?)", [type, name, description, image_url, latitude, longitude], function (err) {
if (err) {
return console.error(err.message);
}
@ -25,8 +32,8 @@ app.get('/add-item', (req, res) => {
});
// Retrieve all items from the database
app.get('/get-items', (req, res) => {
db.all("SELECT * FROM items", [], (err, rows) => {
app.get('/getRuschi', (req, res) => {
db.all("SELECT * FROM ruschi", [], (err, rows) => {
if (err) {
return console.error(err.message);
}
@ -34,6 +41,29 @@ app.get('/get-items', (req, res) => {
});
});
app.get('/login', (req, res) => {
const username = req.body.username;
const password = bcrypt.Hash(req.body.password);
db.all("SELECT * FROM user WHERE " + username + ' AND ' + password, [], (err, rows) => {
if (err) {
return console.error(err.message);
}
res.json('OK');
});
});
app.get('/register', (req, res) => {
const username = req.body.username;
const password = bcrypt.Hash(req.body.password);
db.run('insert into users (username, password) VALUES (?)', [username, password], (err, rows) => {
if (err) {
return console.error(err.message);
}
res.json('OK');
});
});
// Start the server
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);