feat(admin): LicServer config manageable via admin settings UI
Some checks failed
Staging Build / build (push) Has been cancelled
Some checks failed
Staging Build / build (push) Has been cancelled
- Migration: add licserver_base_url/api_key cols to settings table - New: lib/actions/licserver-config.ts (read/write/test server actions) - Updated: proxy routes read config from DB with env-var fallback - Updated: admin/einstellungen adds LicServer card with URL + API key input, show/hide toggle, Save and Connection Test buttons
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { createClient } from '@/lib/supabase/server'
|
||||
import { getLicServerConfig } from '@/lib/actions/licserver-config'
|
||||
import type { PartnerDtoPagedResult, LicServerProblemDetails } from '@/lib/types/licserver'
|
||||
|
||||
const LICSERVER_BASE_URL = process.env.LICSERVER_BASE_URL
|
||||
const LICSERVER_API_KEY = process.env.LICSERVER_API_KEY
|
||||
|
||||
/**
|
||||
* GET /api/licserver/partners
|
||||
*
|
||||
@@ -12,7 +10,8 @@ const LICSERVER_API_KEY = process.env.LICSERVER_API_KEY
|
||||
* Query params forwarded: search, page, pageSize
|
||||
*
|
||||
* Secured: requires a valid Supabase session.
|
||||
* The X-Api-Key is injected server-side and never exposed to the browser.
|
||||
* base_url + api_key are read from DB settings (admin-configurable),
|
||||
* with fallback to LICSERVER_BASE_URL / LICSERVER_API_KEY env vars.
|
||||
*/
|
||||
export async function GET(req: NextRequest) {
|
||||
// ── Auth guard ─────────────────────────────────────────────────────────
|
||||
@@ -22,18 +21,19 @@ export async function GET(req: NextRequest) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
// ── Env check ──────────────────────────────────────────────────────────
|
||||
if (!LICSERVER_BASE_URL || !LICSERVER_API_KEY) {
|
||||
console.error('[licserver] LICSERVER_BASE_URL or LICSERVER_API_KEY not set')
|
||||
// ── Load config from DB (falls back to env vars) ──────────────────────
|
||||
const cfg = await getLicServerConfig()
|
||||
if (!cfg.base_url || !cfg.api_key) {
|
||||
console.error('[licserver] base_url or api_key not configured (DB or env)')
|
||||
return NextResponse.json(
|
||||
{ error: 'LicServer not configured' },
|
||||
{ error: 'LicServer nicht konfiguriert. Bitte in den Admin-Einstellungen hinterlegen.' },
|
||||
{ status: 503 }
|
||||
)
|
||||
}
|
||||
|
||||
// ── Forward query params ───────────────────────────────────────────────
|
||||
const { searchParams } = req.nextUrl
|
||||
const upstream = new URL(`${LICSERVER_BASE_URL}/api-v1/partners`)
|
||||
const upstream = new URL(`${cfg.base_url}/api-v1/partners`)
|
||||
const search = searchParams.get('search')
|
||||
const page = searchParams.get('page')
|
||||
const pageSize = searchParams.get('pageSize')
|
||||
@@ -46,7 +46,7 @@ export async function GET(req: NextRequest) {
|
||||
const res = await fetch(upstream.toString(), {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'X-Api-Key': LICSERVER_API_KEY,
|
||||
'X-Api-Key': cfg.api_key,
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
// Internal container network — short timeout
|
||||
|
||||
Reference in New Issue
Block a user