feat: add /api/internal/roles endpoint for OA integration + middleware publicPaths

This commit is contained in:
aiyimickey 2026-07-07 18:34:46 +08:00
parent b3b10cb162
commit 90d65d3fb2
2 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,17 @@
// GET /api/internal/roles — 供 OA 查询 monitor 支持的角色列表
import { NextResponse } from 'next/server'
import { ROLE_DEFAULT_PERMISSIONS, PERMISSIONS } from '@/lib/permissions'
const INTERNAL_KEY = process.env.INTERNAL_API_KEY || 'oa-internal-key-tlyq-2026'
export async function GET(request: Request) {
const key = request.headers.get('x-internal-key')
if (key !== INTERNAL_KEY) return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
const roles = Object.keys(ROLE_DEFAULT_PERMISSIONS).map(name => ({
name,
permissions: ROLE_DEFAULT_PERMISSIONS[name].map(k => PERMISSIONS.find(p => p.key === k)?.name || k),
}))
return NextResponse.json({ roles })
}

View File

@ -9,6 +9,7 @@ export const middleware = createMiddlewareV2({
cookieDomain, cookieDomain,
allowedIssuers: ['*'], allowedIssuers: ['*'],
enableApiKey: false, enableApiKey: false,
publicPaths: ['/login', '/api/auth', '/api/health', '/api/internal', '/_next', '/favicon.ico'],
}) })
export const config = { matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'] } export const config = { matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'] }