Created
October 2, 2024 15:56
-
-
Save kiritocode1/cfcc5dab24c2475dfebb13214fe09ce3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! blog.localhost:3000/ -> hidden(localhost:3000/articles) | |
//? subdomain.vercel.app -> hidden(vercel.app/{subdomain}) | |
import { NextRequest, NextResponse } from "next/server"; | |
//?? domains -> settings -> *.example.com | |
// /api -> haspermission() -> 403 -> redirect to / | |
// addnewblog.domain -> writetodb() -> redirect to / | |
//! capable to do this | |
//! protected routes , auth , rerouting , cookies and stuff | |
export default async function middleware(req: NextRequest, res: NextResponse) { | |
const url = req.nextUrl; | |
console.log("url is ->", url); | |
let hostname = req.headers.get("host")!; | |
//! blog.aryank.online | |
let currentHost = ""; | |
if (process.env.NODE_ENV === "production") { | |
const baseDomain = "aryank.online"; | |
currentHost = hostname.replace(`.${baseDomain}`, ""); | |
} else { | |
currentHost = hostname.replace(".localhost:3000", ""); | |
} | |
//* blog.aryank.online -> blog | |
console.log("currentHost is ->", currentHost); | |
// too many redirects | |
// Prevent too many redirects | |
if (currentHost.includes("blog") ) { | |
return NextResponse.rewrite(new URL(`/articles`, req.url)); | |
} else { | |
return NextResponse.next(); | |
} | |
} | |
//! coolify | |
//! aws amplify | |
//! aws Cdk({ }) | |
// react router + react | |
export const config = { | |
matcher : "/" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment