Skip to main content
Glama
+server.ts1.6 kB
import { json } from '@sveltejs/kit' import type { RequestHandler } from './$types' import { dev } from '$app/environment' import path from 'path' import { fileURLToPath } from 'url' import { migrate } from 'postgres-migrations/src/index' import { maybeInitializePool } from '$lib/server/db' import { logWarningAlways } from '$lib/log' export const GET: RequestHandler = async () => { const __filename = fileURLToPath(import.meta.url) const __dirname = path.dirname(__filename) const messages: string[] = [] const errors: string[] = [] try { // Initialize the database pool - this will now throw if it fails const client = maybeInitializePool() if (!client) { throw new Error('Failed to initialize database connection pool') } const migrationsPath = dev ? `${__dirname}/../../../../migrations` : '/app/migrations' const migrations = await migrate({ client }, migrationsPath) migrations.forEach((migration) => messages.push(`✅ ${migration.fileName}`)) messages.push('🏁 Migrations completed') } catch (e) { logWarningAlways('Migration error:', e) const errorMessage = e instanceof Error ? e.message : 'Unknown error occurred' errors.push(errorMessage) // Add more helpful error messages for common issues if (errorMessage.includes('connection') || errorMessage.includes('pool')) { errors.push('Please check your database connection settings in DB_URL environment variable') } } // Return appropriate status code based on success/failure const status = errors.length > 0 ? 500 : 200 return json( { messages, errors }, { status } ) }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/khromov/llmctx'

If you have feedback or need assistance with the MCP directory API, please join our Discord server