Troubleshooting¶
Common issues and solutions when using REROUTE.
Import Errors¶
Adapter Import Error¶
Symptoms:
ImportError: cannot import name 'FlaskAdapter' from 'reroute'
ImportError: Flask adapter is not available
Root Cause:
REROUTE now focuses exclusively on FastAPI. Other framework adapters are not available.
Solution:
Use FastAPIAdapter instead:
# Correct usage:
from reroute import FastAPIAdapter
from fastapi import FastAPI
from config import AppConfig
app = FastAPI(title="My API")
adapter = FastAPIAdapter(app, app_dir="./app", config=AppConfig)
adapter.register_routes()
If you're migrating from another framework, see FastAPI Integration for guidance.
Routes Not Being Registered¶
Symptoms: - Routes return 404 errors - Route files exist but aren't accessible
Common Causes:
- Incorrect file structure: Route files must be in
app/routes/<route-name>/page.py - Missing RouteBase: Route class must inherit from
RouteBase - No HTTP methods: Class must have at least one method (get, post, put, delete)
Solution:
Ensure proper structure:
# page.py
from reroute import RouteBase
class HelloRoutes(RouteBase):
def get(self):
return {"message": "Hello"}
Port Already in Use¶
Symptoms:
Solution:
Change the port in config.py:
Or kill the process using the port:
# Windows
netstat -ano | findstr :7376
taskkill /PID <process_id> /F
# Linux/Mac
lsof -ti:7376 | xargs kill -9
Routes Not Appearing in Swagger UI¶
Symptoms:
- Swagger UI loads successfully but shows no API endpoints
- OpenAPI JSON at /docs/openapi.json has empty "paths": {}
- Routes work correctly when tested with curl or browser
Common Causes:
- OpenAPI disabled: Check if
OpenAPI.ENABLE = Truein config - Wrong port: Ensure you're accessing the correct port
- Routes not registered: Verify
adapter.register_routes()is called
Solution:
# config.py
class AppConfig(Config):
class OpenAPI:
ENABLE = True # Enable OpenAPI docs
DOCS_PATH = "/docs" # Swagger UI endpoint
JSON_PATH = "/openapi.json" # OpenAPI spec endpoint
# main.py
adapter.register_routes() # Don't forget this!
ModuleNotFoundError¶
Symptoms:
Solution:
Install all dependencies:
Or install FastAPI directly:
Configuration Issues¶
IndentationError in Generated config.py¶
Symptoms:
Root Cause:
In earlier versions (before v0.1.4), the Jinja2 template had multiple configuration statements on a single line.
Solution:
Fixed in v0.1.4+. If you have an old project, manually fix your config.py:
# BEFORE (WRONG):
REDOC_PATH = None ... JSON_PATH = "/openapi.json"
# AFTER (CORRECT):
REDOC_PATH = None
JSON_PATH = "/openapi.json"
CORS Errors in Browser¶
Symptoms: - Browser console shows CORS errors - API works with curl but fails from web frontend
Solution:
Enable and configure CORS in your config.py:
class AppConfig(Config):
ENABLE_CORS = True
CORS_ALLOW_ORIGINS = ["http://localhost:3000"] # Your frontend URL
CORS_ALLOW_METHODS = ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"]
CORS_ALLOW_HEADERS = ["*"]
CORS_ALLOW_CREDENTIALS = True
Performance Issues¶
Slow Route Discovery¶
Symptoms: - Application takes a long time to start - Many route files
Solution:
REROUTE caches discovered routes. If you have performance issues:
- Reduce the number of nested route folders
- Use class-based routes instead of many small files
- Check for circular imports in route files
Memory Issues¶
Symptoms: - Application uses too much memory - Memory usage grows over time
Solution:
The @cache decorator has built-in LRU eviction with bounded storage (1000 entries max). If you need more control:
from reroute.decorators import cache
# Configure cache limits
@cache(max_entries=500, duration=60) # Keep only 500 entries
def get_data():
return expensive_operation()
Need More Help?¶
If you encounter issues not covered here:
- Check the Installation Troubleshooting for setup issues
- Review the Examples for working code
- Check the API Reference for detailed documentation
- Report bugs at GitHub Issues