Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# node-webapp
Die node-webapp enthält das javascript Frontend und einen node Server!Test!!
Die node-webapp enthält das javascript Frontend und einen node Server!
40 changes: 24 additions & 16 deletions backend/server.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import connectDB from './config/db.js'
import express from 'express'
import dotenv from 'dotenv'
import connectDB from './config/db.js';
import express from 'express';
import bodyParser from 'body-parser';
import dotenv from 'dotenv';

//connect database
connectDB()
// Connect database
connectDB();

//dotenv config
dotenv.config()
// Load environment variables
dotenv.config();

const app = express()
const app = express();
const PORT = process.env.PORT || 3000;

// Serve static files from the 'public' directory
app.use(express.static('../frontend/public'));



const PORT = process.env.PORT || 3000

//Express js listen method to run project on http://localhost:3000
app.listen(PORT, console.log(`App is running in ${process.env.NODE_ENV} mode on port ${PORT}`))
app.use(bodyParser.json());

// Route to receive GeoJSON data
app.post('/uploadGeoJSON', (req, res) => {
const geoJSONData = req.body;
// Add logic here to work with the GeoJSON data
console.log('Received GeoJSON data:', geoJSONData);
res.status(200).json({ message: 'GeoJSON data received successfully' });
});

// Express.js listen method to run the project on http://localhost:3000
app.listen(PORT, () => {
console.log(`App is running in ${process.env.NODE_ENV} mode on port ${PORT}`);
});
70 changes: 0 additions & 70 deletions frontend/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<link rel="stylesheet" href="https://unpkg.com/leaflet-draw@1.0.2/dist/leaflet.draw.css" />

<!-- Externe CSS-Datei -->
<link rel="stylesheet" href="../src/styles.css">
<link rel="stylesheet" href="styles.css">
</head>

<body class="bg-light">
Expand Down
22 changes: 22 additions & 0 deletions frontend/public/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,28 @@ function saveTime() {
console.log('Start Date:', startDate);
console.log('End Date:', endDate);

// Get GeoJSON data from the drawn layer
const geoJSONData = drawnItems.toGeoJSON();

// Make an HTTP POST request to send GeoJSON data to the server
fetch('http://localhost:3000/uploadGeoJSON', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
startDate,
endDate,
geoJSONData,
}),
})
.then(response => response.json())
.then(data => {
console.log('Server response:', data);
})
.catch(error => {
console.error('Error sending data to the server:', error);
});
// Close the popup after saving
map.closePopup();
}
Expand Down
File renamed without changes.