Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo Site: move admin redirect and dam rewrite into middleware #2727

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions demo/site/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,6 @@ const cometConfig = require("./src/comet-config.json");
* @type {import('next').NextConfig}
**/
const nextConfig = {
async rewrites() {
return [
{
source: "/dam/:path*",
destination: process.env.API_URL + "/dam/:path*",
},
];
},
async redirects() {
const adminUrl = process.env.ADMIN_URL;

if (!adminUrl) {
throw Error("ADMIN_URL is not defined");
}
return [
{
source: "/admin",
destination: adminUrl,
permanent: false,
},
];
},
images: {
deviceSizes: cometConfig.dam.allowedImageSizes,
},
Expand Down
8 changes: 8 additions & 0 deletions demo/site/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ export async function middleware(request: NextRequest) {
return NextResponse.rewrite(new URL(predefinedPageRewrite, request.url));
}

if (pathname.startsWith("/dam/")) {
return NextResponse.rewrite(new URL(`${process.env.API_URL_INTERNAL}${request.nextUrl.pathname}`));
}

if (request.nextUrl.pathname === "/admin" && process.env.ADMIN_URL) {
return NextResponse.redirect(new URL(process.env.ADMIN_URL));
}

return NextResponse.next();
}

Expand Down
Loading