2022-04-12 19:21:32 +00:00
|
|
|
import { NextURL } from "next/dist/server/web/next-url";
|
2022-04-09 22:50:13 +00:00
|
|
|
import { NextRequest, NextResponse } from "next/server";
|
|
|
|
|
|
|
|
export async function middleware(req: NextRequest) {
|
|
|
|
const { pathname, searchParams } = req.nextUrl;
|
|
|
|
|
|
|
|
if (pathname === "/dashboards") {
|
|
|
|
const dashboardId = searchParams.get("dashboardId");
|
|
|
|
if (dashboardId) {
|
|
|
|
return NextResponse.redirect(
|
|
|
|
new URL(`/dashboards/view/${dashboardId}`, req.url)
|
|
|
|
);
|
|
|
|
}
|
2022-04-29 17:58:21 +00:00
|
|
|
} else if (pathname === "/capture") {
|
|
|
|
return NextResponse.redirect(new URL("/", req.url));
|
2022-04-12 19:21:32 +00:00
|
|
|
} else if (pathname === "/secretDashboard") {
|
|
|
|
const dashboardId = searchParams.get("dashboardId");
|
|
|
|
if (dashboardId) {
|
|
|
|
const url = new URL(`/dashboards/embed/${dashboardId}`, req.url);
|
|
|
|
const numCols = searchParams.get("numCols");
|
|
|
|
if (numCols) {
|
|
|
|
url.searchParams.set("numCols", numCols);
|
|
|
|
}
|
|
|
|
return NextResponse.redirect(url);
|
|
|
|
} else {
|
|
|
|
return NextResponse.rewrite(new NextURL("/404", req.url));
|
|
|
|
}
|
2022-04-09 22:50:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NextResponse.next();
|
|
|
|
}
|