Fixed url pattern in the doc for path-based shops

This commit is contained in:
2025-11-18 23:18:13 +01:00
parent b3009e3795
commit f14686c131
8 changed files with 68 additions and 52 deletions

View File

@@ -6,6 +6,8 @@
There are three ways depending on the deployment mode:
**⚠️ Important:** This guide describes **customer-facing shop routes**. For vendor dashboard/management routes, see [Vendor Dashboard Documentation](../../vendor/). The shop uses `/vendors/{code}/shop/*` (plural) in path-based mode, while the vendor dashboard uses `/vendor/{code}/*` (singular).
### 1. **SUBDOMAIN MODE** (Production - Recommended)
```
https://VENDOR_SUBDOMAIN.platform.com/shop/products
@@ -26,11 +28,11 @@ https://shop.techpro.io/shop/cart
### 3. **PATH-BASED MODE** (Development Only)
```
http://localhost:PORT/vendor/VENDOR_CODE/shop/products
http://localhost:PORT/vendors/VENDOR_CODE/shop/products
Example:
http://localhost:8000/vendor/acme/shop/products
http://localhost:8000/vendor/techpro/shop/checkout
http://localhost:8000/vendors/acme/shop/products
http://localhost:8000/vendors/techpro/shop/checkout
```
---
@@ -107,15 +109,15 @@ id | vendor_id | domain | is_active | is_verified
### 3. PATH-BASED MODE (Development Only)
**URL Pattern:** `http://localhost:PORT/vendor/VENDOR_CODE/shop/...`
**URL Pattern:** `http://localhost:PORT/vendors/VENDOR_CODE/shop/...`
**Example:**
- Development: `http://localhost:8000/vendor/acme/shop/products`
- With port: `http://localhost:8000/vendor/acme/shop/products/123`
- Development: `http://localhost:8000/vendors/acme/shop/products`
- With port: `http://localhost:8000/vendors/acme/shop/products/123`
**How It Works:**
1. Developer visits `http://localhost:8000/vendor/acme/shop/products`
2. `vendor_context_middleware` detects path-based routing pattern `/vendor/acme/...`
1. Developer visits `http://localhost:8000/vendors/acme/shop/products`
2. `vendor_context_middleware` detects path-based routing pattern `/vendors/acme/...`
3. Extracts vendor code `"acme"` from the path
4. Looks up Vendor: `SELECT * FROM vendors WHERE subdomain = 'acme'`
5. Sets `request.state.vendor = Vendor(acme)`
@@ -151,12 +153,12 @@ https://acme.wizamart.com/shop/account/profile → Profile (Auth Require
### Path-Based (DEVELOPMENT)
```
http://localhost:8000/vendor/acme/shop/ → Homepage
http://localhost:8000/vendor/acme/shop/products → Products
http://localhost:8000/vendor/acme/shop/products/123 → Product Detail
http://localhost:8000/vendor/acme/shop/cart → Cart
http://localhost:8000/vendor/acme/shop/checkout → Checkout
http://localhost:8000/vendor/acme/shop/account/login → Login
http://localhost:8000/vendors/acme/shop/ → Homepage
http://localhost:8000/vendors/acme/shop/products → Products
http://localhost:8000/vendors/acme/shop/products/123 → Product Detail
http://localhost:8000/vendors/acme/shop/cart → Cart
http://localhost:8000/vendors/acme/shop/checkout → Checkout
http://localhost:8000/vendors/acme/shop/account/login → Login
```
### API Endpoints (Same for All Modes)
@@ -350,9 +352,9 @@ In Jinja2 template:
The `vendor_context_middleware` sets `clean_path` for path-based URLs, but this isn't used for FastAPI routing.
**Problem:**
- Incoming: `GET http://localhost:8000/vendor/acme/shop/products`
- Incoming: `GET http://localhost:8000/vendors/acme/shop/products`
- Routes registered: `@router.get("/shop/products")`
- FastAPI tries to match `/vendor/acme/shop/products` against `/shop/products`
- FastAPI tries to match `/vendors/acme/shop/products` against `/shop/products`
- Result: ❌ 404 Not Found
**Solution (Recommended):**
@@ -374,7 +376,7 @@ app.middleware("http")(path_rewrite_middleware)
Or alternatively, mount the router twice:
```python
app.include_router(shop_pages.router, prefix="/shop")
app.include_router(shop_pages.router, prefix="/vendor") # Allows /vendor/* paths
app.include_router(shop_pages.router, prefix="/vendors/{vendor_code}/shop") # Path-based development mode
```
---
@@ -401,7 +403,7 @@ Set-Cookie: customer_token=eyJ...; Path=/shop; HttpOnly; SameSite=Lax
|------|-----|----------|-----|-----|
| Subdomain | `vendor.platform.com/shop` | Production (standard) | *.platform.com | Add subdomains |
| Custom Domain | `vendor-domain.com/shop` | Production (premium) | Per vendor | Vendor configures |
| Path-Based | `localhost:8000/vendor/v/shop` | Development only | None | None |
| Path-Based | `localhost:8000/vendors/v/shop` | Development only | None | None |
---