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
|
# ENVIRONMENT=production
|
||||||
# FRONTEND_ORIGIN=https://urmiai.com
|
# FRONTEND_ORIGIN=https://urmiai.com
|
||||||
# CORS_ORIGINS=https://urmiai.com,http://urmiai.com,https://www.urmiai.com,http://www.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
|
# VITE_API_URL=
|
||||||
# GOOGLE_REDIRECT_URI=https://api.urmiai.com/api/v1/auth/google/callback
|
# GOOGLE_REDIRECT_URI=https://urmiai.com/api/v1/auth/google/callback
|
||||||
# VOICE_RELAY_PUBLIC_URL=wss://api.urmiai.com/api/v1/voice
|
# VOICE_RELAY_PUBLIC_URL=wss://urmiai.com/api/v1/voice
|
||||||
|
|
||||||
# Ultronsms gateway credentials (backend only)
|
# Ultronsms gateway credentials (backend only)
|
||||||
ULTRONSMS_BASE_URL=https://ultronsms.com
|
ULTRONSMS_BASE_URL=https://ultronsms.com
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@ services:
|
||||||
ports:
|
ports:
|
||||||
- "5173:5173"
|
- "5173:5173"
|
||||||
environment:
|
environment:
|
||||||
VITE_API_URL: ${VITE_API_URL:-http://localhost:8000}
|
VITE_API_URL: ${VITE_API_URL:-}
|
||||||
|
VITE_PROXY_TARGET: http://backend:8000
|
||||||
volumes:
|
volumes:
|
||||||
- ./frontend/src:/app/src
|
- ./frontend/src:/app/src
|
||||||
- ./frontend/public:/app/public
|
- ./frontend/public:/app/public
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,6 @@
|
||||||
#
|
#
|
||||||
# Vite only exposes variables prefixed with VITE_ to the browser.
|
# 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
|
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,
|
type VoiceCall,
|
||||||
} from '../../lib/api'
|
} 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 }) {
|
function FieldRow({ label, value }: { label: string; value: string }) {
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import {
|
||||||
} from '../../lib/api'
|
} from '../../lib/api'
|
||||||
import { buildMessage, splitTemplate } from '../messaging/templateUtils'
|
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 = [
|
const OTP_TEMPLATE_TYPES = [
|
||||||
{ type: 'general_verification', name: 'General Verification' },
|
{ 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 { useCallback, useEffect, useRef, useState } from 'react'
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
import { numbersApi, voiceApi, type PhoneNumber, type VoiceApiDocs, type VoiceCall } from '../../lib/api'
|
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'
|
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) {
|
function formatPhone(value: string) {
|
||||||
if (value.length === 10) return `${value.slice(0, 5)} ${value.slice(5)}`
|
if (value.length === 10) return `${value.slice(0, 5)} ${value.slice(5)}`
|
||||||
return value
|
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 = {
|
export type DashboardResponse = {
|
||||||
metrics: {
|
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 { defineConfig } from 'vite'
|
||||||
import react from '@vitejs/plugin-react'
|
import react from '@vitejs/plugin-react'
|
||||||
|
|
||||||
|
const proxyTarget = process.env.VITE_PROXY_TARGET ?? 'http://localhost:8000'
|
||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
|
|
@ -8,5 +10,12 @@ export default defineConfig({
|
||||||
host: true,
|
host: true,
|
||||||
// Required when Caddy (or another proxy) forwards urmiai.com to the dev server
|
// Required when Caddy (or another proxy) forwards urmiai.com to the dev server
|
||||||
allowedHosts: ['urmiai.com', 'www.urmiai.com', 'localhost'],
|
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