Skip to content

Fix Werkzeug production error and auto-init SQLite database#1

Open
seeyoui-2024 wants to merge 2 commits into
kocatekin:mainfrom
seeyoui-2024:fix-werkzeug-production-warning
Open

Fix Werkzeug production error and auto-init SQLite database#1
seeyoui-2024 wants to merge 2 commits into
kocatekin:mainfrom
seeyoui-2024:fix-werkzeug-production-warning

Conversation

@seeyoui-2024

Copy link
Copy Markdown

Fixes

  1. Fix Werkzeug production error

    • Add allow_unsafe_werkzeug=True to socketio.run()
    • Resolves RuntimeError: The Werkzeug web server is not designed to run in production when running in Docker
  2. Auto-initialize database

    • Automatically create SQLite database and table on application startup
    • Execute CREATE TABLE IF NOT EXISTS sensor_data if table does not exist
    • Prevents API errors on first deployment due to missing database

Changed Files

  • restapi.py:
    • Add import os

    • Add init_db() function for automatic database initialization

  • Dockerfile:
    • Add allow_unsafe_werkzeug=True to socketio.run()

Testing

  • Docker build succeeds
  • Container starts without Werkzeug error
  • Database and table auto-created on first startup
  • Data read/write operations work correctly

Flask-SocketIO detects that you are using Werkzeug's built-in server in a production environment (or an environment it recognizes as non-development). This usage is prohibited by default, as Werkzeug is not designed for production and poses security and performance risks.
Automatically creates the database and tables if they do not exist on application startup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant