diff --git a/nuxt.config.ts b/nuxt.config.ts index 70cb3f8..c3e2d19 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -2,7 +2,7 @@ export default defineNuxtConfig({ ssr: false, compatibilityDate: "2024-11-01", 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: { head: { titleTemplate: "%s • Port Nimara Portal", @@ -109,18 +109,6 @@ export default defineNuxtConfig({ // Trust proxy headers for proper HTTPS detection experimental: { 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: { diff --git a/plugins/00.startup-check.client.ts b/plugins/00.startup-check.client.ts new file mode 100644 index 0000000..331a919 --- /dev/null +++ b/plugins/00.startup-check.client.ts @@ -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) + } +}) diff --git a/plugins/00.startup-check.server.ts b/plugins/00.startup-check.server.ts new file mode 100644 index 0000000..5fc2c99 --- /dev/null +++ b/plugins/00.startup-check.server.ts @@ -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 + } +}) diff --git a/server/api/health.ts b/server/api/health.ts new file mode 100644 index 0000000..71e24d3 --- /dev/null +++ b/server/api/health.ts @@ -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' + }) + } +})