Add VERCEL_URl to env with URL parsing & transformation

This commit is contained in:
Xevion
2023-02-17 02:28:18 -06:00
parent 0e1c7f4af5
commit d649c4ea5e

View File

@@ -15,6 +15,12 @@ const server = z.object({
* To expose them to the client, prefix them with `NEXT_PUBLIC_`.
*/
const client = z.object({
NEXT_PUBLIC_APP_URL: z.string().transform(url => {
// Add a HTTPS url prefix automatically, for vercel.
if (!(url.startsWith("http://") || url.startsWith("https://")))
return `https://${url}`;
return url;
})
// NEXT_PUBLIC_CLIENTVAR: z.string().min(1),
});
@@ -25,6 +31,7 @@ const client = z.object({
*/
const processEnv = {
NODE_ENV: process.env.NODE_ENV,
NEXT_PUBLIC_APP_URL: process.env.VERCEL_URL ?? process.env.APP_URL
// NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR,
};