removing legacy code on path_rewrite_middleware
This commit is contained in:
@@ -112,25 +112,29 @@ request.state.vendor_id = 1
|
||||
request.state.clean_path = "/shop/products"
|
||||
```
|
||||
|
||||
### 4. PathRewriteMiddleware
|
||||
### 4. Router Matching (FastAPI Native)
|
||||
|
||||
**What happens**:
|
||||
- Checks if `clean_path` is different from original path
|
||||
- If different, rewrites the request path for FastAPI routing
|
||||
- FastAPI matches the request path against registered routes
|
||||
- For path-based development mode, routes are registered with two prefixes:
|
||||
- `/shop/*` for subdomain/custom domain
|
||||
- `/vendors/{vendor_code}/shop/*` for path-based development
|
||||
|
||||
**Example** (Path-Based Mode):
|
||||
|
||||
```python
|
||||
# Input (path-based development mode)
|
||||
original_path = "/vendors/WIZAMART/shop/products"
|
||||
clean_path = "/shop/products" # From VendorContextMiddleware
|
||||
# In main.py - Double router mounting
|
||||
app.include_router(shop_pages.router, prefix="/shop")
|
||||
app.include_router(shop_pages.router, prefix="/vendors/{vendor_code}/shop")
|
||||
|
||||
# Path rewrite
|
||||
if clean_path != original_path:
|
||||
request.scope['path'] = clean_path
|
||||
request._url = request.url.replace(path=clean_path)
|
||||
# Request: /vendors/WIZAMART/shop/products
|
||||
# Matches: Second router (/vendors/{vendor_code}/shop)
|
||||
# Route: @router.get("/products")
|
||||
# vendor_code available as path parameter = "WIZAMART"
|
||||
```
|
||||
|
||||
**Note:** Previous implementations used `PathRewriteMiddleware` to rewrite paths. This has been replaced with FastAPI's native routing via double router mounting.
|
||||
|
||||
**Request State After**: No changes to state, but internal path updated
|
||||
|
||||
### 5. ContextDetectionMiddleware
|
||||
|
||||
Reference in New Issue
Block a user