mirror of
https://github.com/apidoorman/doorman.git
synced 2026-02-08 10:08:49 -06:00
gateway api fix
This commit is contained in:
@@ -584,6 +584,20 @@ doorman = FastAPI(
|
||||
openapi_url='/platform/openapi.json',
|
||||
)
|
||||
|
||||
# Middleware to handle X-Forwarded-Proto for correct HTTPS redirects behind reverse proxy
|
||||
@doorman.middleware('http')
|
||||
async def forwarded_proto_middleware(request: Request, call_next):
|
||||
"""Handle X-Forwarded-Proto header to fix FastAPI redirects behind reverse proxy.
|
||||
|
||||
When behind Nginx/reverse proxy, FastAPI sees requests as HTTP even when they're HTTPS.
|
||||
This causes automatic trailing slash redirects to use http:// instead of https://.
|
||||
This middleware updates the request scope to use the forwarded protocol.
|
||||
"""
|
||||
forwarded_proto = request.headers.get('x-forwarded-proto')
|
||||
if forwarded_proto:
|
||||
request.scope['scheme'] = forwarded_proto
|
||||
return await call_next(request)
|
||||
|
||||
# Enable analytics collection middleware for request/response metrics
|
||||
try:
|
||||
setup_analytics_middleware(doorman)
|
||||
|
||||
@@ -56,7 +56,7 @@ const AddRoutingPage = () => {
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
|
||||
await postJson(`${SERVER_URL}/platform/routing/`, formData)
|
||||
await postJson(`${SERVER_URL}/platform/routing`, formData)
|
||||
|
||||
router.push('/routings')
|
||||
} catch (err) {
|
||||
|
||||
@@ -140,7 +140,7 @@ const AddUserPage = () => {
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
|
||||
await postJson(`${SERVER_URL}/platform/user/`, formData)
|
||||
await postJson(`${SERVER_URL}/platform/user`, formData)
|
||||
|
||||
router.push('/users')
|
||||
} catch (err) {
|
||||
|
||||
@@ -1,23 +1,30 @@
|
||||
// Gateway URL from environment - required for API calls
|
||||
// Set NEXT_PUBLIC_GATEWAY_URL in root .env file (loaded via dotenv-cli for dev, build arg for Docker)
|
||||
let GATEWAY_URL = process.env.NEXT_PUBLIC_GATEWAY_URL || ''
|
||||
|
||||
// Auto-upgrade HTTP to HTTPS if the page is loaded over HTTPS
|
||||
// This must happen BEFORE any module evaluation
|
||||
if (typeof window !== 'undefined' && window.location.protocol === 'https:' && GATEWAY_URL.startsWith('http://')) {
|
||||
GATEWAY_URL = GATEWAY_URL.replace('http://', 'https://')
|
||||
console.log('[CONFIG] Auto-upgraded GATEWAY_URL to HTTPS:', GATEWAY_URL)
|
||||
}
|
||||
const GATEWAY_URL_RAW = process.env.NEXT_PUBLIC_GATEWAY_URL || ''
|
||||
|
||||
let _cachedUrl: string | null = null
|
||||
|
||||
const getApiUrl = (): string => {
|
||||
// On client side, check if we need to re-evaluate due to HTTPS upgrade
|
||||
if (typeof window !== 'undefined' && _cachedUrl !== null && _cachedUrl.startsWith('http://') && window.location.protocol === 'https:') {
|
||||
// Clear cache to force re-evaluation with HTTPS upgrade
|
||||
_cachedUrl = null
|
||||
}
|
||||
|
||||
// Return cached value if already computed
|
||||
if (_cachedUrl !== null) {
|
||||
return _cachedUrl
|
||||
}
|
||||
|
||||
// 1. Use gateway URL from env if set
|
||||
let GATEWAY_URL = GATEWAY_URL_RAW
|
||||
|
||||
// Auto-upgrade HTTP to HTTPS if the page is loaded over HTTPS
|
||||
if (typeof window !== 'undefined' && window.location.protocol === 'https:' && GATEWAY_URL.startsWith('http://')) {
|
||||
GATEWAY_URL = GATEWAY_URL.replace('http://', 'https://')
|
||||
console.log('[CONFIG] Auto-upgraded GATEWAY_URL to HTTPS:', GATEWAY_URL)
|
||||
}
|
||||
|
||||
if (GATEWAY_URL) {
|
||||
console.log('[CONFIG] Using GATEWAY_URL from env:', GATEWAY_URL)
|
||||
_cachedUrl = GATEWAY_URL
|
||||
|
||||
Reference in New Issue
Block a user