proxy routing issue'
This commit is contained in:
parent
0d42ff72d3
commit
d077292bbc
9 changed files with 42 additions and 17 deletions
|
|
@ -21,9 +21,9 @@ GOOGLE_REDIRECT_URI=http://localhost:8000/api/v1/auth/google/callback
|
|||
# ENVIRONMENT=production
|
||||
# FRONTEND_ORIGIN=https://urmiai.com
|
||||
# CORS_ORIGINS=https://urmiai.com,http://urmiai.com,https://www.urmiai.com,http://www.urmiai.com
|
||||
# VITE_API_URL=https://api.urmiai.com
|
||||
# GOOGLE_REDIRECT_URI=https://api.urmiai.com/api/v1/auth/google/callback
|
||||
# VOICE_RELAY_PUBLIC_URL=wss://api.urmiai.com/api/v1/voice
|
||||
# VITE_API_URL=
|
||||
# GOOGLE_REDIRECT_URI=https://urmiai.com/api/v1/auth/google/callback
|
||||
# VOICE_RELAY_PUBLIC_URL=wss://urmiai.com/api/v1/voice
|
||||
|
||||
# Ultronsms gateway credentials (backend only)
|
||||
ULTRONSMS_BASE_URL=https://ultronsms.com
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ services:
|
|||
ports:
|
||||
- "5173:5173"
|
||||
environment:
|
||||
VITE_API_URL: ${VITE_API_URL:-http://localhost:8000}
|
||||
VITE_API_URL: ${VITE_API_URL:-}
|
||||
VITE_PROXY_TARGET: http://backend:8000
|
||||
volumes:
|
||||
- ./frontend/src:/app/src
|
||||
- ./frontend/public:/app/public
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@
|
|||
#
|
||||
# Vite only exposes variables prefixed with VITE_ to the browser.
|
||||
|
||||
# Backend API base URL (no trailing slash)
|
||||
# Backend API base URL (no trailing slash). Leave empty behind Caddy+Vite proxy.
|
||||
VITE_API_URL=http://localhost:8000
|
||||
# Production: VITE_API_URL=https://api.urmiai.com
|
||||
# Production (same-origin via Vite proxy): VITE_API_URL=
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import {
|
|||
type VoiceCall,
|
||||
} from '../../lib/api'
|
||||
|
||||
const API_BASE_URL = import.meta.env.VITE_API_URL ?? 'http://localhost:8000'
|
||||
import { API_BASE_URL } from '../../lib/apiBase'
|
||||
|
||||
function FieldRow({ label, value }: { label: string; value: string }) {
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import {
|
|||
} from '../../lib/api'
|
||||
import { buildMessage, splitTemplate } from '../messaging/templateUtils'
|
||||
|
||||
const API_BASE_URL = import.meta.env.VITE_API_URL ?? 'http://localhost:8000'
|
||||
import { API_BASE_URL } from '../../lib/apiBase'
|
||||
|
||||
const OTP_TEMPLATE_TYPES = [
|
||||
{ type: 'general_verification', name: 'General Verification' },
|
||||
|
|
|
|||
|
|
@ -2,16 +2,9 @@ import { Mic, MicOff, Phone, PhoneOutgoing, Radio, ShieldCheck } from 'lucide-re
|
|||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { numbersApi, voiceApi, type PhoneNumber, type VoiceApiDocs, type VoiceCall } from '../../lib/api'
|
||||
import { API_BASE_URL, wsBaseUrl } from '../../lib/apiBase'
|
||||
import { UrmiConsoleAudio, extractStreamId, type AudioPermissionState } from './voiceAudio'
|
||||
|
||||
const API_BASE_URL = import.meta.env.VITE_API_URL ?? 'http://localhost:8000'
|
||||
|
||||
function wsBaseUrl() {
|
||||
const url = new URL(API_BASE_URL)
|
||||
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:'
|
||||
return url.origin
|
||||
}
|
||||
|
||||
function formatPhone(value: string) {
|
||||
if (value.length === 10) return `${value.slice(0, 5)} ${value.slice(5)}`
|
||||
return value
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
const API_BASE_URL = import.meta.env.VITE_API_URL ?? 'http://localhost:8000'
|
||||
import { API_BASE_URL } from './apiBase'
|
||||
|
||||
export type DashboardResponse = {
|
||||
metrics: {
|
||||
|
|
|
|||
22
frontend/src/lib/apiBase.ts
Normal file
22
frontend/src/lib/apiBase.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
const configured = import.meta.env.VITE_API_URL
|
||||
|
||||
/**
|
||||
* API base URL for browser requests.
|
||||
* - unset → local dev default (http://localhost:8000)
|
||||
* - empty string → same origin (/api proxied by Vite behind Caddy)
|
||||
* - https://... → explicit API host
|
||||
*/
|
||||
export const API_BASE_URL =
|
||||
configured === undefined
|
||||
? 'http://localhost:8000'
|
||||
: configured.replace(/\/$/, '')
|
||||
|
||||
export function wsBaseUrl(): string {
|
||||
if (API_BASE_URL) {
|
||||
const url = new URL(API_BASE_URL)
|
||||
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:'
|
||||
return url.origin
|
||||
}
|
||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
|
||||
return `${protocol}//${window.location.host}`
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
const proxyTarget = process.env.VITE_PROXY_TARGET ?? 'http://localhost:8000'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
|
|
@ -8,5 +10,12 @@ export default defineConfig({
|
|||
host: true,
|
||||
// Required when Caddy (or another proxy) forwards urmiai.com to the dev server
|
||||
allowedHosts: ['urmiai.com', 'www.urmiai.com', 'localhost'],
|
||||
// Same-origin API: browser calls urmiai.com/api/*, Vite forwards to backend
|
||||
proxy: {
|
||||
'/api': { target: proxyTarget, changeOrigin: true, ws: true },
|
||||
'/health': { target: proxyTarget, changeOrigin: true },
|
||||
'/docs': { target: proxyTarget, changeOrigin: true },
|
||||
'/openapi.json': { target: proxyTarget, changeOrigin: true },
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue