Skip to content

Commit 3808cb7

Browse files
committed
chore: minor change on route
1 parent 604b4b4 commit 3808cb7

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

app/[locale]/next-data/og/route.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@ import { ImageResponse } from 'next/og';
22

33
import HexagonGrid from '@/components/Icons/HexagonGrid';
44
import JsIconWhite from '@/components/Icons/Logos/JsIconWhite';
5-
import { ENABLE_STATIC_EXPORT, VERCEL_REVALIDATE } from '@/next.constants.mjs';
5+
import {
6+
ENABLE_STATIC_EXPORT,
7+
VERCEL_ENV,
8+
VERCEL_REVALIDATE,
9+
} from '@/next.constants.mjs';
610
import { defaultLocale } from '@/next.locales.mjs';
711
import tailwindConfig from '@/tailwind.config';
812
import { hexToRGBA } from '@/util/hexToRGBA';
913

14+
// This is the default type of blog post type that we use for OG
15+
const defaultTypeParam = 'announcement';
16+
1017
// This is the Route Handler for the `GET` method which handles the request
1118
// for generating OpenGrapgh images for Blog Posts and Pages
1219
// @see https://nextjs.org/docs/app/building-your-application/routing/router-handlers
@@ -17,8 +24,8 @@ export const GET = async (request: Request) => {
1724
const hasTitle = searchParams.has('title');
1825
const title = hasTitle ? searchParams.get('title')?.slice(0, 100) : undefined;
1926

20-
//?type=<type> - if undefined default to announcement
21-
const typeParam = searchParams.get('type') ?? 'announcement';
27+
// ?type=<type> - if undefined default to announcement
28+
const typeParam = searchParams.get('type') ?? defaultTypeParam;
2229

2330
const typeAttributes: { [key: string]: string } = {
2431
announcement: tailwindConfig.theme.colors.green['700'],
@@ -27,8 +34,7 @@ export const GET = async (request: Request) => {
2734
};
2835

2936
// use the mapped value, or if not found use announcement
30-
const type =
31-
typeAttributes[typeParam] ?? tailwindConfig.theme.colors.green['700'];
37+
const type = typeAttributes[typeParam] ?? typeAttributes[defaultTypeParam];
3238

3339
const gridBackground = `radial-gradient(circle, ${hexToRGBA(type)}, transparent)`;
3440

@@ -55,7 +61,8 @@ export const generateStaticParams = async () => [
5561
];
5662

5763
// We want to use `edge` runtime when using Vercel
58-
export const runtime = process.env.NEXT_PUBLIC_VERCEL_URL ? 'edge' : false;
64+
// @see https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#runtime
65+
export const runtime = VERCEL_ENV ? 'edge' : 'nodejs';
5966

6067
// Enforces that only the paths from `generateStaticParams` are allowed, giving 404 on the contrary
6168
// @see https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamicparams

0 commit comments

Comments
 (0)