fix: Vite type declaration, non-idempotent retry, hardcoded test IP
- Add frontend/src/vite-env.d.ts (reference vite/client) to fix vue-tsc build - Restrict axios-retry to GET/HEAD/OPTIONS only (avoid replaying mutations) - Convert test_upstream.py to accept URL via CLI args instead of hardcoded IP
This commit is contained in:
@@ -6,11 +6,18 @@ from app.services.upstream_client import UpstreamClient
|
|||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
# Usage: python test_upstream.py <base_url> [api_prefix] [auth_type] [token]
|
||||||
|
# Example: python test_upstream.py http://localhost:8000 "" bearer "sk-xxx"
|
||||||
|
import sys
|
||||||
|
base_url = sys.argv[1] if len(sys.argv) > 1 else "http://localhost:8000"
|
||||||
|
api_prefix = sys.argv[2] if len(sys.argv) > 2 else ""
|
||||||
|
auth_type = sys.argv[3] if len(sys.argv) > 3 else "bearer"
|
||||||
|
token = sys.argv[4] if len(sys.argv) > 4 else ""
|
||||||
with UpstreamClient(
|
with UpstreamClient(
|
||||||
base_url="http://170.106.100.210:55555",
|
base_url=base_url,
|
||||||
api_prefix="",
|
api_prefix=api_prefix,
|
||||||
auth_type="bearer",
|
auth_type=auth_type,
|
||||||
auth_config={"token": ""}, # We don't have token, but /api/group/ in some new-api may be open, or fail with 401
|
auth_config={"token": token},
|
||||||
timeout=10.0,
|
timeout=10.0,
|
||||||
) as client:
|
) as client:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -11,14 +11,17 @@ export const api = axios.create({
|
|||||||
axiosRetry(api, {
|
axiosRetry(api, {
|
||||||
retries: 3,
|
retries: 3,
|
||||||
retryDelay: axiosRetry.exponentialDelay,
|
retryDelay: axiosRetry.exponentialDelay,
|
||||||
|
onRetry: (_retryCount, _err, _requestConfig) => {
|
||||||
|
// no-op — could log in dev
|
||||||
|
},
|
||||||
|
// Only retry idempotent methods — never retry POST/PUT/PATCH/DELETE
|
||||||
retryCondition: (err) => {
|
retryCondition: (err) => {
|
||||||
|
const method = (err.config?.method ?? '').toUpperCase()
|
||||||
|
if (!['GET', 'HEAD', 'OPTIONS'].includes(method)) return false
|
||||||
// Retry on network errors or 5xx, but never on 401/403/404/4xx
|
// Retry on network errors or 5xx, but never on 401/403/404/4xx
|
||||||
if (!err.response) return true
|
if (!err.response) return true
|
||||||
return err.response.status >= 500 && err.response.status < 600
|
return err.response.status >= 500 && err.response.status < 600
|
||||||
},
|
},
|
||||||
onRetry: (_retryCount, _err, _requestConfig) => {
|
|
||||||
// no-op — could log in dev
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
api.interceptors.response.use(
|
api.interceptors.response.use(
|
||||||
|
|||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
/// <reference types="vite/client" />
|
||||||
Reference in New Issue
Block a user