august 2024
august 2024
Everything that we want to allow to be overriden on specific jobboard
interface Route {
name: string;
targetPath: string; // Next.js route
path: {
en: string;
de: string;
sk: string;
cs: string;
hr: string;
};
meta?: {
authRequired?: boolean;
};
}
apiVersion: cyborg/v1
kind: Routes
metadata:
name: default
spec:
homepage:
targetPath: '/'
path:
en: '/'
de: '/'
sk: '/'
cs: '/'
hr: '/'
search_results:
targetPath: '/search-results'
path:
en: '/work'
de: '/arbeit-suchen'
sk: '/praca'
cs: '/nabidky'
hr: '/pretraga-poslova'
advert:
targetPath: '/advert/:advertId'
path:
en: '/work/:advertId'
de: '/arbeit/:advertId'
sk: '/praca/:advertId'
cs: '/nabidka/:advertId'
hr: '/posao/:advertId'
function ListingItem() {
const { createPath } = useRoutes();
return (
<>
<Link href={createPath('advert', { advertId: 123, utmSource: 'listing'})}>Detail</Link>
<>
);
}
export async function middleware(request: NextRequest) {
const requestData = routingMiddleware(request);
const requestHeaders = new Headers(request.headers);
requestHeaders.set('x-locale', requestData.locale);
requestHeaders.set('x-correlation-id', generateCorrelationId());
requestHeaders.set('x-request-url', request.url);
if (!requestData.currentRoute) {
return NextResponse.rewrite(new URL('not-found', request.url), {
request: {
headers: requestHeaders,
},
});
}
return NextResponse.rewrite(new URL(requestData.targetUrl, request.url), {
request: {
headers: requestHeaders,
},
});
}