File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change 11import { redirect } from 'next/navigation' ;
22import { NextRequest } from 'next/server' ;
3- import { BadgeTemplateType , BadgeType } from '@/badge/badge.types' ;
3+ import { BadgeTemplateType , BadgeType , ThemeType } from '@/badge/badge.types' ;
44import { renderSmallBadge } from '@/badge/templates/small/small.render' ;
55import { renderMediumBadge } from '@/badge/templates/medium/medium.render' ;
66
@@ -16,12 +16,12 @@ const getRendererByTemplate = (template: BadgeTemplateType) => {
1616} ;
1717
1818export async function GET ( req : NextRequest , { params } : Props ) {
19- const theme = 'light' ;
2019 const { login } = await params ;
2120
2221 const searchParams = req . nextUrl . searchParams ;
2322 const type = searchParams . get ( 'type' ) as BadgeType ;
2423 const template = searchParams . get ( 'template' ) as BadgeTemplateType ;
24+ const theme = ( searchParams . get ( 'theme' ) ?? 'light' ) as ThemeType ;
2525
2626 const svg = await getRendererByTemplate ( template ) ( { theme, login, type } ) ;
2727
Original file line number Diff line number Diff line change 11import { NextRequest , NextResponse } from 'next/server' ;
22
33export async function POST ( req : NextRequest ) {
4+ const isProd = process . env . NODE_ENV === 'production' ;
5+
6+ if ( isProd ) {
7+ const origin = req . headers . get ( 'origin' ) || req . headers . get ( 'referer' ) ;
8+ const host = req . headers . get ( 'host' ) ;
9+ const protocol = req . headers . get ( 'x-forwarded-proto' ) || 'https' ;
10+ const expectedOrigin = `${ protocol } ://${ host } ` ;
11+
12+ if ( ! origin || ! origin . startsWith ( expectedOrigin ) ) {
13+ return NextResponse . json ( { error : 'Forbidden' } , { status : 403 } ) ;
14+ }
15+ }
16+
417 try {
518 const { query, variables } = await req . json ( ) ;
619
You can’t perform that action at this time.
0 commit comments