Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server: Switch from Django to Flask #48

Merged
merged 18 commits into from
May 20, 2024
Merged

Conversation

H1ghBre4k3r
Copy link
Collaborator

@H1ghBre4k3r H1ghBre4k3r commented May 15, 2024

This PR refactors the server, such that we switch from Django to Flask. All currently defined custom routes are ported. However, the django-internal routes are not ported and need to be created manually (or we find a valid substitution for them). This PR utilizes SQLAlchemy to create a connection with the database, together with flask_migrate to create and manage migrations for the database scheme.

Furthermore, this PR adds lifecycle and house keeping scripts for performing common tasks like setting up a workspace, starting the server, cleaning up the local files, or performing database migrations.

Closes #39

Updated the Pipfile to replace the Django package with Flask. This change was made
to switch the web framework being used in the project.
This commit refactors the code to use flask instead of django. :)
Added Flask-SQLAlchemy and Flask-Migrate dependencies to the project to enable database functionality and migrations. Made changes to Pipfile, requirements.txt, and updated app.py to integrate these libraries.
Furthermore, this commit adds scripts for performing house keeping actions like creating migrations, applying them, etc.
@H1ghBre4k3r H1ghBre4k3r added enhancement New feature or request backend Every issue, regarding the backend development database Every issue, regarding the database development labels May 15, 2024
@H1ghBre4k3r H1ghBre4k3r added this to the Pre-Alpha Setup milestone May 15, 2024
@H1ghBre4k3r H1ghBre4k3r self-assigned this May 15, 2024
@H1ghBre4k3r H1ghBre4k3r requested a review from YIllmann May 15, 2024 20:00
Refactored register_player() function to improve error handling and return
a proper HTTP 400 response when an invalid TAN is detected. The response is
now created using Response directly.
server/web/api.py Outdated Show resolved Hide resolved
server/scripts/start-server.sh Outdated Show resolved Hide resolved
- Installed Flask-WTF for CSRF protection in app.py
- Integrated CSRF protection in app initialization in app.py
- Removed unused function and updated requirements.txt and Pipfile configurations
@7erra
Copy link
Collaborator

7erra commented May 16, 2024

Wie sieht die Trennung zwischen Flask Backend und React Frontend aus? Mmn brauchen wir dafür einen neuen Unterordner oder auf Projektebene einen neuen. Oder benutzen wir doch Jinja auf Python Basis?

@H1ghBre4k3r
Copy link
Collaborator Author

Wie sieht die Trennung zwischen Flask Backend und React Frontend aus? Mmn brauchen wir dafür einen neuen Unterordner oder auf Projektebene einen neuen. Oder benutzen wir doch Jinja auf Python Basis?

Dafür würde ich evtl einfach einen neuen Ordner "Frontend" machen, in dem das dann lebt. Oder einen src Ordner, aus dem dass dan fröhlich in einen public-Ordner generiert wird. Ich kann das tatsächlich auch schonmal aus PoC mit einbauen.

server/web/api.py Outdated Show resolved Hide resolved
server/web/api.py Outdated Show resolved Hide resolved
server/web/api.py Outdated Show resolved Hide resolved
server/web/api.py Outdated Show resolved Hide resolved
Add scripts to build and start the frontend in the Makefile.
Also updated the app.py file to serve the frontend files.
Refactored the Flask API responses in api.py to remove the unnecessary 
use of jsonify and streamline the return statements for better readability 
and consistency. Updated the get_current_exec_status and hello_world 
functions to return dictionaries directly instead of using jsonify. 
Also updated the register_player function to return the exec_id directly.
Added redirect to "/" when the path is empty in the serve function to ensure that the root path redirects to the index.html page.
@YIllmann
Copy link
Collaborator

Wie im Call besprochen: um eine einheitliche BE/FE Trennung hinzubekommen wäre eine Auslagerung des Fronentordners manvsim-frontend sinnvoll. Außerdem würde ich das dann auch umbenennen in web-frontend. Dann können sich die Appler später da auch einfinden und ihren Kram dazu programmieren.
Die Struktur könnte sein:
MANVSIM:

  • app (fluttr und co)
  • server (Flask Backend)
  • web (React frontend)

@H1ghBre4k3r H1ghBre4k3r merged commit b1334fe into main May 20, 2024
2 checks passed
@H1ghBre4k3r H1ghBre4k3r deleted the feature/server/switch-to-flask branch June 18, 2024 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Every issue, regarding the backend development database Every issue, regarding the database development enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch to Flask
3 participants