Skip to content

Scheduling infrastructure for absolutely everyone.

Adds custom rewrite logic for hosted cal.com

zomars9e5b1f121f0a
diff --git a/apps/web/next.config.js b/apps/web/next.config.js
index 688cd7060d6..a4251b149cc 100644
--- a/apps/web/next.config.js
+++ b/apps/web/next.config.js
@@ -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 = [