From ae4e745886e32496c07bf32999e93c390a6d4049 Mon Sep 17 00:00:00 2001 From: iflei01 <61976075+iflei01@users.noreply.github.com> Date: Mon, 18 Dec 2023 15:56:34 +0100 Subject: [PATCH] =?UTF-8?q?NodeVerbindung=20Frontend=20f=C3=BCr=20Datei-Up?= =?UTF-8?q?load=20HTTP=20Request;=20styles.css=20verschoben?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- backend/server.js | 40 ++++++++++------- frontend/README.md | 70 ----------------------------- frontend/public/index.html | 2 +- frontend/public/script.js | 22 +++++++++ frontend/{src => public}/styles.css | 0 6 files changed, 48 insertions(+), 88 deletions(-) delete mode 100644 frontend/README.md rename frontend/{src => public}/styles.css (100%) diff --git a/README.md b/README.md index d511cf4..c14534a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # node-webapp -Die node-webapp enthält das javascript Frontend und einen node Server!Test!! \ No newline at end of file +Die node-webapp enthält das javascript Frontend und einen node Server! \ No newline at end of file diff --git a/backend/server.js b/backend/server.js index d75e240..948fa68 100644 --- a/backend/server.js +++ b/backend/server.js @@ -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}`); +}); \ No newline at end of file diff --git a/frontend/README.md b/frontend/README.md deleted file mode 100644 index 58beeac..0000000 --- a/frontend/README.md +++ /dev/null @@ -1,70 +0,0 @@ -# Getting Started with Create React App - -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). - -## Available Scripts - -In the project directory, you can run: - -### `npm start` - -Runs the app in the development mode.\ -Open [http://localhost:3000](http://localhost:3000) to view it in your browser. - -The page will reload when you make changes.\ -You may also see any lint errors in the console. - -### `npm test` - -Launches the test runner in the interactive watch mode.\ -See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. - -### `npm run build` - -Builds the app for production to the `build` folder.\ -It correctly bundles React in production mode and optimizes the build for the best performance. - -The build is minified and the filenames include the hashes.\ -Your app is ready to be deployed! - -See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. - -### `npm run eject` - -**Note: this is a one-way operation. Once you `eject`, you can't go back!** - -If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. - -Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. - -You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. - -## Learn More - -You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). - -To learn React, check out the [React documentation](https://reactjs.org/). - -### Code Splitting - -This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) - -### Analyzing the Bundle Size - -This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) - -### Making a Progressive Web App - -This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) - -### Advanced Configuration - -This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) - -### Deployment - -This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) - -### `npm run build` fails to minify - -This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) diff --git a/frontend/public/index.html b/frontend/public/index.html index e87a496..50c8699 100644 --- a/frontend/public/index.html +++ b/frontend/public/index.html @@ -14,7 +14,7 @@ - + diff --git a/frontend/public/script.js b/frontend/public/script.js index 1d76a0e..dd149e9 100644 --- a/frontend/public/script.js +++ b/frontend/public/script.js @@ -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(); } diff --git a/frontend/src/styles.css b/frontend/public/styles.css similarity index 100% rename from frontend/src/styles.css rename to frontend/public/styles.css