At geolytix we have a ton [100+
] of projects sharing our development [geolytix.dev] and production [geolytix.xyz] domains.
In order to use the same domain for all projects we have a rewrite project which has function defined which is never used only to get the project deployed.
{ "version": 2, "trailingSlash": false, "rewrites": [ { "source": "/client_a", "destination": "https://dev-client-a.vercel.app/client_a" }, { "source": "/client_a/(.*)", "destination": "https://dev-client-a.vercel.app/client_a/$1" }, { "source": "/client_b", "destination": "https://dev-client-b.vercel.app/client_b" }, { "source": "/client_b/(.*)", "destination": "https://dev-client-b.vercel.app/client_b/$1" }, { "source": "/geodata", "destination": "https://dev-geodata.vercel.app/geodata"},{ "source": "/geodata/(.*)", "destination": "https://dev-geodata.vercel.app/geodata/$1"}] }
Each project listed in the rewrites project uses a unique path in its own rewrites.
For example these are the rewrites for the https://dev-geodata.vercel.app/geodata project. I removed the headers and some environment variables. The DIR environment variable provides the path to the node api.js function.
{ "version": 2, "build": { "env": { "NODE_ENV": "production" } }, "functions": { "api/api.js": { "includeFiles": "public/**" } }, "trailingSlash": false, "rewrites": [ { "source": "/geodata/public/(.*)", "destination": "/$1" }, { "source": "/geodata/api/query/:_template?", "destination": "/api/api.js" }, { "source": "/geodata/api/location/:method?", "destination": "/api/api.js" }, { "source": "/geodata/api/user/:method?/:key?", "destination": "/api/api.js" }, { "source": "/geodata/api/workspace/:key?", "destination": "/api/api.js" }, { "source": "/geodata/api/layer/:format?/:z?/:x?/:y?", "destination": "/api/api.js" }, { "source": "/geodata/api/provider/:provider?", "destination": "/api/api.js" }, { "source": "/geodata/public/(.*)", "destination": "/$1" }, { "source": "/geodata/api/(.*)", "destination": "/api/api.js" }, { "source": "/geodata/view/:_template?", "destination": "/api/api.js" }, { "source": "/geodata", "destination": "/api/api.js" }, { "source": "/", "destination": "/api/api.js" } ], "env": { "TITLE": "GEOLYTIX | GEODATA", "DIR": "/geodata" }}The rewrites project allows us to access the https://dev-geodata.vercel.app/geodata project from the shared domain ie https://geolytix.dev/geodata
We build this logic about 4 years ago when we had a dozen projects, not a ton of projects.
It would be interested to hear whether there is smarter way to share a domain and rewrite different paths on that domain to different projects.
