Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-tey committed Sep 29, 2023
1 parent 2435c66 commit 1ed55b1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions app/[domain]/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ export async function generateStaticParams() {
},
},
},
// feel free to remove this filter if you want to generate paths for all posts
where: {
site: {
subdomain: "demo",
},
},
});

const allPaths = allPosts
Expand Down
4 changes: 4 additions & 0 deletions app/[domain]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export async function generateStaticParams() {
subdomain: true,
customDomain: true,
},
// feel free to remove this filter if you want to generate paths for all sites
where: {
subdomain: "demo",
},
});

const allPaths = allSites
Expand Down
6 changes: 5 additions & 1 deletion lib/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ export const updateSite = withSiteAuth(
customDomain: value,
},
});
await addDomainToVercel(value);
await Promise.all([
addDomainToVercel(value),
// Optional: add www subdomain as well and redirect to apex domain
// addDomainToVercel(`www.${value}`),
]);

// empty value means the user wants to remove the custom domain
} else if (value === "") {
Expand Down
4 changes: 1 addition & 3 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ export default async function middleware(req: NextRequest) {
const url = req.nextUrl;

// Get hostname of request (e.g. demo.vercel.pub, demo.localhost:3000)
let hostname = req.headers
const hostname = req.headers
.get("host")!
.replace(".localhost:3000", `.${process.env.NEXT_PUBLIC_ROOT_DOMAIN}`);

hostname = hostname.replace("www.", ""); // remove www. from domain

const searchParams = req.nextUrl.searchParams.toString();
// Get the pathname of the request (e.g. /, /about, /blog/first-post)
const path = `${url.pathname}${
Expand Down

0 comments on commit 1ed55b1

Please sign in to comment.