Adds custom rewrite logic for hosted cal.com

This commit is contained in:
zomars 2022-07-13 15:03:09 -06:00
parent 179da11f4b
commit 9e5b1f121f

View File

@ -84,20 +84,63 @@ const nextConfig = {
return config;
},
async rewrites() {
return [
{
source: "/:user/avatar.png",
destination: "/api/user/avatar?username=:user",
},
{
source: "/team/:teamname/avatar.png",
destination: "/api/user/avatar?teamname=:teamname",
},
/* TODO: have these files being served from another deployment or CDN {
source: "/embed/embed.js",
destination: process.env.NEXT_PUBLIC_EMBED_LIB_URL?,
}, */
];
const rewrites = {
beforeFiles: [],
afterFiles: [
{
source: "/:user/avatar.png",
destination: "/api/user/avatar?username=:user",
},
{
source: "/team/:teamname/avatar.png",
destination: "/api/user/avatar?teamname=:teamname",
},
/* TODO: have these files being served from another deployment or CDN {
source: "/embed/embed.js",
destination: process.env.NEXT_PUBLIC_EMBED_LIB_URL?,
}, */
],
fallback: [],
};
/** This logic es specific for our `cal.com` hosted version */
if (process.env.NEXT_PUBLIC_WEBAPP_URL === "https://app.cal.com") {
const CAL_WEBSITE_SUBDOMAIN_URL = "https://website.cal.com";
/* Homepage should go to website.cal.com */
rewrites.beforeFiles.push([
{
source: "/",
has: [
{
type: "header",
key: "referer",
value: `${process.env.NEXT_PUBLIC_WEBSITE_URL}/`,
},
],
destination: `${CAL_WEBSITE_SUBDOMAIN_URL}/`,
},
{
source: "/_next/static/:static*",
has: [
{
type: "header",
key: "referer",
value: `${process.env.NEXT_PUBLIC_WEBSITE_URL}/`,
},
],
destination: `${CAL_WEBSITE_SUBDOMAIN_URL}/_next/static/:static*`,
},
]);
/* Everything else should fallback to website.cal.com */
rewrites.fallback.push([
{
source: "/:websitePage*",
destination: CAL_WEBSITE_SUBDOMAIN_URL + "/:websitePage*",
},
]);
}
return rewrites;
},
async redirects() {
const redirects = [