forked from breatheco-de/website-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_middeware.js
More file actions
30 lines (24 loc) · 788 Bytes
/
Copy path_middeware.js
File metadata and controls
30 lines (24 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { NextResponse } from "@vercel/edge";
export const config = {
// Specify the matcher for the routes you want to redirect
matcher: "/:lang/post/:postName*",
};
const getPost = async (slug) => {
const _resp = await axios.get(
process.env.GATSBY_BREATHECODE_HOST + `/registry/asset/${slug}`,
options
);
if (_resp.status != 200) {
logger.error(_resp.data);
throw new Error(_resp.data);
}
return _resp.data;
};
export default function middleware(request) {
const { nextUrl } = request;
const [postLang, _, postSlug] = nextUrl.pathname.split("/")[3];
const post = getPost();
// Construct the destination URL
const destinationUrl = `/us/post_topic_cluster/${postSlug}`;
return NextResponse.redirect(new URL(destinationUrl, request.url));
}