Implement basic auth for frontend
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
# server.py
|
||||
import asyncio
|
||||
import websockets
|
||||
import json
|
||||
@@ -6,7 +7,12 @@ from quart import Quart, jsonify, request
|
||||
from routers.systems import systems_bp
|
||||
from routers.nodes import nodes_bp, register_client, unregister_client
|
||||
from routers.bot import bot_bp
|
||||
from routers.auth import auth_bp # ONLY import auth_bp, not jwt instance from auth.py
|
||||
from internal.db_wrappers import SystemDbController, DiscordIdDbController
|
||||
from internal.auth_wrappers import UserDbController
|
||||
# Import the JWTManager instance and its configuration function
|
||||
from config.jwt_config import jwt, configure_jwt # Import the actual jwt instance and the config function
|
||||
|
||||
|
||||
# --- WebSocket Server Components ---
|
||||
# Dictionary to store active clients: {client_id: websocket}
|
||||
@@ -57,6 +63,12 @@ app.active_clients = active_clients
|
||||
# Create and attach the DB wrappers
|
||||
app.sys_db_h = SystemDbController()
|
||||
app.d_id_db_h = DiscordIdDbController()
|
||||
app.user_db_h = UserDbController()
|
||||
|
||||
# Configure JWT settings and initialize the JWTManager instance with the app
|
||||
configure_jwt(app)
|
||||
jwt.init_app(app) # Crucial: This initializes the global 'jwt' instance with your app
|
||||
|
||||
|
||||
@app.before_serving
|
||||
async def startup_websocket_server():
|
||||
@@ -86,6 +98,7 @@ async def shutdown_websocket_server():
|
||||
app.register_blueprint(systems_bp, url_prefix="/systems")
|
||||
app.register_blueprint(nodes_bp, url_prefix="/nodes")
|
||||
app.register_blueprint(bot_bp, url_prefix="/bots")
|
||||
app.register_blueprint(auth_bp, url_prefix="/auth") # Register the auth blueprint
|
||||
|
||||
@app.route('/')
|
||||
async def index():
|
||||
@@ -93,14 +106,10 @@ async def index():
|
||||
|
||||
# --- Main Execution ---
|
||||
if __name__ == "__main__":
|
||||
# Quart's app.run() will start the asyncio event loop and manage it.
|
||||
# The @app.before_serving decorator ensures the websocket server starts within that loop.
|
||||
# We removed asyncio.run(main()) and the main() function itself.
|
||||
print("Starting Quart API server...")
|
||||
app.run(
|
||||
host="0.0.0.0",
|
||||
port=5000,
|
||||
debug=False # Set to True for development
|
||||
)
|
||||
print("Quart API server stopped.")
|
||||
|
||||
print("Quart API server stopped.")
|
||||
Reference in New Issue
Block a user