DEBUG: Add comprehensive startup checks and improve OIDC configuration
## **Debugging Improvements Added:** ### **Startup Monitoring:** - plugins/00.startup-check.server.ts - Server-side initialization checks - plugins/00.startup-check.client.ts - Client-side debugging - server/api/health.ts - Health check endpoint ### **OIDC Configuration Fixes:** - Reordered modules: uxt-oidc-auth loads after uetify-nuxt-module - Temporarily removed file-based storage configuration (potential issue) - Maintained all session settings and provider configuration ### **Server-Side Checks:** - Auto-creates required directories (./data/oidc-sessions, ./data/sessions) - Validates all required environment variables are present - Logs initialization progress and any errors ### **Client-Side Monitoring:** - Detects OAuth callback URLs for debugging - Checks storage availability - Monitors startup process ### **Health Endpoint:** - /api/health - Check server status and OIDC configuration - Reports environment variables status - Shows uptime and basic system info ## **Expected Results:** Detailed logs will show exactly where initialization fails Health check endpoint works even if OIDC fails Better error handling prevents silent crashes Module loading order fixes potential conflicts Debugging info helps identify the 502 root cause ## **Next Steps:** 1. Deploy this updated container 2. Check startup logs for [STARTUP] messages 3. Test /api/health endpoint first 4. Monitor OAuth callback debugging info 5. Use logs to identify and fix remaining issues This maintains all existing functionality while adding comprehensive debugging!
This commit is contained in:
parent
9ced2518ed
commit
f2e0c3d1b1
|
|
@ -2,7 +2,7 @@ export default defineNuxtConfig({
|
||||||
ssr: false,
|
ssr: false,
|
||||||
compatibilityDate: "2024-11-01",
|
compatibilityDate: "2024-11-01",
|
||||||
devtools: { enabled: true },
|
devtools: { enabled: true },
|
||||||
modules: ["nuxt-directus", "nuxt-oidc-auth", "vuetify-nuxt-module", "@vite-pwa/nuxt"],
|
modules: ["nuxt-directus", "vuetify-nuxt-module", "nuxt-oidc-auth", "@vite-pwa/nuxt"],
|
||||||
app: {
|
app: {
|
||||||
head: {
|
head: {
|
||||||
titleTemplate: "%s • Port Nimara Portal",
|
titleTemplate: "%s • Port Nimara Portal",
|
||||||
|
|
@ -109,18 +109,6 @@ export default defineNuxtConfig({
|
||||||
// Trust proxy headers for proper HTTPS detection
|
// Trust proxy headers for proper HTTPS detection
|
||||||
experimental: {
|
experimental: {
|
||||||
wasm: true
|
wasm: true
|
||||||
},
|
|
||||||
storage: {
|
|
||||||
// Configure persistent storage for OIDC sessions
|
|
||||||
'oidc:sessions': {
|
|
||||||
driver: 'fs',
|
|
||||||
base: './data/oidc-sessions'
|
|
||||||
},
|
|
||||||
// Configure storage for general session data
|
|
||||||
'sessions': {
|
|
||||||
driver: 'fs',
|
|
||||||
base: './data/sessions'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
oidc: {
|
oidc: {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
export default defineNuxtPlugin(async () => {
|
||||||
|
// Client-side startup checks
|
||||||
|
console.log('[STARTUP] Client-side initialization starting...')
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Check if OIDC is available
|
||||||
|
if (process.client) {
|
||||||
|
console.log('[STARTUP] Client environment detected')
|
||||||
|
console.log('[STARTUP] Current URL:', window.location.href)
|
||||||
|
|
||||||
|
// Check for OAuth callback
|
||||||
|
if (window.location.pathname.includes('/auth/keycloak/callback')) {
|
||||||
|
console.log('[STARTUP] OAuth callback detected - URL:', window.location.href)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check localStorage for any existing sessions
|
||||||
|
const hasStorage = typeof Storage !== 'undefined'
|
||||||
|
console.log('[STARTUP] Storage available:', hasStorage)
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('[STARTUP] Client-side initialization complete')
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[STARTUP] Client-side initialization error:', error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
import { mkdir } from 'fs/promises'
|
||||||
|
import { existsSync } from 'fs'
|
||||||
|
import { join } from 'path'
|
||||||
|
|
||||||
|
export default defineNitroPlugin(async (nitroApp) => {
|
||||||
|
console.log('[STARTUP] Server-side initialization starting...')
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Ensure data directories exist
|
||||||
|
const dataDir = './data'
|
||||||
|
const oidcSessionsDir = './data/oidc-sessions'
|
||||||
|
const sessionsDir = './data/sessions'
|
||||||
|
|
||||||
|
console.log('[STARTUP] Checking storage directories...')
|
||||||
|
|
||||||
|
// Create directories if they don't exist
|
||||||
|
const dirs = [dataDir, oidcSessionsDir, sessionsDir]
|
||||||
|
for (const dir of dirs) {
|
||||||
|
if (!existsSync(dir)) {
|
||||||
|
console.log(`[STARTUP] Creating directory: ${dir}`)
|
||||||
|
await mkdir(dir, { recursive: true })
|
||||||
|
console.log(`[STARTUP] Successfully created: ${dir}`)
|
||||||
|
} else {
|
||||||
|
console.log(`[STARTUP] Directory exists: ${dir}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check environment variables
|
||||||
|
console.log('[STARTUP] Checking OIDC environment variables...')
|
||||||
|
const requiredEnvVars = [
|
||||||
|
'NUXT_OIDC_TOKEN_KEY',
|
||||||
|
'NUXT_OIDC_SESSION_SECRET',
|
||||||
|
'NUXT_OIDC_AUTH_SESSION_SECRET',
|
||||||
|
'NUXT_OIDC_PROVIDERS_KEYCLOAK_CLIENT_SECRET'
|
||||||
|
]
|
||||||
|
|
||||||
|
for (const envVar of requiredEnvVars) {
|
||||||
|
const value = process.env[envVar]
|
||||||
|
if (value) {
|
||||||
|
console.log(`[STARTUP] ✅ ${envVar}: present (length: ${value.length})`)
|
||||||
|
} else {
|
||||||
|
console.error(`[STARTUP] ❌ ${envVar}: MISSING`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('[STARTUP] Server-side initialization complete')
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[STARTUP] Server-side initialization error:', error)
|
||||||
|
// Don't throw - let the app continue with fallback behavior
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
try {
|
||||||
|
return {
|
||||||
|
status: 'healthy',
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
uptime: process.uptime(),
|
||||||
|
environment: process.env.NODE_ENV || 'development',
|
||||||
|
oidc: {
|
||||||
|
configured: !!process.env.NUXT_OIDC_TOKEN_KEY,
|
||||||
|
hasClientSecret: !!process.env.NUXT_OIDC_PROVIDERS_KEYCLOAK_CLIENT_SECRET
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 500,
|
||||||
|
statusMessage: 'Health check failed',
|
||||||
|
data: error instanceof Error ? error.message : 'Unknown error'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
Loading…
Reference in New Issue