Browse Source

fix: allow kubernetes

pull/122/head
Bruno Bernard 6 months ago
parent
commit
321c4606f5
  1. 7
      web/lib/auth.ts
  2. 23
      web/lib/httpServerClient.ts

7
web/lib/auth.ts

@ -125,13 +125,6 @@ export const authOptions = {
strategy: 'jwt',
},
callbacks: {
async redirect({ url, baseUrl }) {
// Always return relative redirects (avoids needing NEXTAUTH_URL)
if (url.startsWith("/")) return `${baseUrl}${url}`;
// Ensure only safe redirects
if (new URL(url).origin === baseUrl) return url;
return baseUrl;
},
async jwt({ token, user, trigger, session }) {
if (trigger === 'update') {
if (session.name !== token.name) {

23
web/lib/httpServerClient.ts

@ -5,14 +5,27 @@ import { Session } from 'next-auth'
// Create a base URL that works in Docker container network if running in a container
// or falls back to the public URL if not in a container
const getServerSideBaseUrl = () => {
// When running server-side in Docker, use the service name from docker-compose
const getServerSideBaseUrl = (): string => {
// Prefer explicit public API base URL if set
if (process.env.NEXT_PUBLIC_API_BASE_URL) {
return process.env.NEXT_PUBLIC_API_BASE_URL
}
// Detect Kubernetes environment
if (process.env.KUBERNETES_SERVICE_HOST) {
console.log("Detected Kubernetes environment")
return process.env.NEXT_PUBLIC_API_BASE_URL || ''
}
// Detect Docker container runtime
if (process.env.CONTAINER_RUNTIME === 'docker') {
console.log('Running in Docker container')
console.log("Detected Docker container environment")
return 'http://textbee-api:3001/api/v1'
}
// Otherwise use the public URL
return process.env.NEXT_PUBLIC_API_BASE_URL || ''
// Fallback to empty string if nothing else matches
return ''
}
export const httpServerClient = axios.create({

Loading…
Cancel
Save