fix(website): edge-config fallback

This commit is contained in:
iCrawl
2023-04-02 18:30:00 +02:00
parent 6aba9e99eb
commit 0645bf0f7f
2 changed files with 26 additions and 22 deletions

View File

@@ -5,24 +5,26 @@ import type { ServerRuntime } from 'next/types';
export const runtime: ServerRuntime = 'edge'; export const runtime: ServerRuntime = 'edge';
export async function GET() { export async function GET() {
const url = await get<string>('DISCORD_WEBHOOK_URL'); try {
const imageUrl = await get<string>('IT_IS_WEDNESDAY_MY_DUDES'); const url = await get<string>('DISCORD_WEBHOOK_URL');
if (url && imageUrl) { const imageUrl = await get<string>('IT_IS_WEDNESDAY_MY_DUDES');
await fetch(url, { if (url && imageUrl) {
method: 'POST', await fetch(url, {
headers: { 'Content-Type': 'application/json' }, method: 'POST',
body: JSON.stringify({ headers: { 'Content-Type': 'application/json' },
username: 'It is wednesday, my dudes', body: JSON.stringify({
embeds: [ username: 'It is wednesday, my dudes',
{ embeds: [
image: { {
url: imageUrl, image: {
url: imageUrl,
},
}, },
}, ],
], }),
}), });
}); }
} } catch {}
return NextResponse.json({ message: 'It is wednesday, my dudes' }); return NextResponse.json({ message: 'It is wednesday, my dudes' });
} }

View File

@@ -11,11 +11,13 @@ async function fetchLatestVersion(packageName: string) {
export default async function middleware(request: NextRequest) { export default async function middleware(request: NextRequest) {
if (request.nextUrl.pathname === '/docs') { if (request.nextUrl.pathname === '/docs') {
const skip = await get<boolean>('SKIP_PACKAGE_VERSION_SELECTION'); try {
if (skip) { const skip = await get<boolean>('SKIP_PACKAGE_VERSION_SELECTION');
const latestVersion = await fetchLatestVersion('builders'); if (skip) {
return NextResponse.redirect(new URL(`/docs/packages/builders/${latestVersion}`, request.url)); const latestVersion = await fetchLatestVersion('builders');
} return NextResponse.redirect(new URL(`/docs/packages/builders/${latestVersion}`, request.url));
}
} catch {}
} }
if (request.nextUrl.pathname.includes('discord.js')) { if (request.nextUrl.pathname.includes('discord.js')) {