-
Notifications
You must be signed in to change notification settings - Fork 959
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: mobile and desktop resolver (#2923)
- Loading branch information
Showing
14 changed files
with
162 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { createEnv } from "@t3-oss/env-core" | ||
import { z } from "zod" | ||
|
||
export const isDev = | ||
"process" in globalThis ? process.env.NODE_ENV === "development" : import.meta.env.DEV | ||
export const env = createEnv({ | ||
clientPrefix: "VITE_", | ||
client: { | ||
VITE_WEB_URL: z.string().url().default("https://app.follow.is"), | ||
VITE_API_URL: z.string(), | ||
VITE_DEV_PROXY: z.string().optional(), | ||
VITE_SENTRY_DSN: z.string().optional(), | ||
VITE_INBOXES_EMAIL: z.string().default("@follow.re"), | ||
VITE_FIREBASE_CONFIG: z.string().optional(), | ||
|
||
VITE_OPENPANEL_CLIENT_ID: z.string().optional(), | ||
VITE_OPENPANEL_API_URL: z.string().url().optional(), | ||
|
||
// For external, use api_url if you don't want to fill it in. | ||
VITE_EXTERNAL_PROD_API_URL: z.string().optional(), | ||
VITE_EXTERNAL_DEV_API_URL: z.string().optional(), | ||
VITE_EXTERNAL_API_URL: z.string().optional(), | ||
VITE_WEB_PROD_URL: z.string().optional(), | ||
VITE_WEB_DEV_URL: z.string().optional(), | ||
}, | ||
|
||
emptyStringAsUndefined: true, | ||
runtimeEnv: getRuntimeEnv() as any, | ||
|
||
skipValidation: "process" in globalThis ? process.env.VITEST === "true" : false, | ||
}) | ||
|
||
function metaEnvIsEmpty() { | ||
try { | ||
return Object.keys(import.meta.env || {}).length === 0 | ||
} catch { | ||
return true | ||
} | ||
} | ||
|
||
function getRuntimeEnv() { | ||
try { | ||
if (metaEnvIsEmpty()) { | ||
return process.env | ||
} | ||
return injectExternalEnv(import.meta.env) | ||
} catch { | ||
return process.env | ||
} | ||
} | ||
|
||
declare const globalThis: any | ||
function injectExternalEnv<T>(originEnv: T): T { | ||
if (!("document" in globalThis)) { | ||
return originEnv | ||
} | ||
const prefix = "__followEnv" | ||
const env = globalThis[prefix] | ||
if (!env) { | ||
return originEnv | ||
} | ||
|
||
for (const key in env) { | ||
originEnv[key as keyof T] = env[key] | ||
} | ||
return originEnv | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const profile = "prod" | ||
|
||
const appEndpointMap = { | ||
prod: { | ||
VITE_API_URL: "https://api.follow.is", | ||
VITE_WEB_URL: "https://app.follow.is", | ||
VITE_INBOXES_EMAIL: "@follow.re", | ||
}, | ||
dev: { | ||
VITE_API_URL: "https://api.dev.follow.is", | ||
VITE_WEB_URL: "https://dev.follow.is", | ||
VITE_INBOXES_EMAIL: "[email protected]", | ||
}, | ||
staging: { | ||
VITE_API_URL: "https://api.follow.is", | ||
VITE_WEB_URL: "https://staging.follow.is", | ||
VITE_INBOXES_EMAIL: "@follow.re", | ||
}, | ||
} | ||
|
||
export const env = { | ||
VITE_WEB_URL: appEndpointMap[profile].VITE_WEB_URL, | ||
VITE_API_URL: appEndpointMap[profile].VITE_API_URL, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,23 @@ | ||
import { createEnv } from "@t3-oss/env-core" | ||
import { z } from "zod" | ||
|
||
export const isDev = | ||
"process" in globalThis ? process.env.NODE_ENV === "development" : import.meta.env.DEV | ||
export const env = createEnv({ | ||
clientPrefix: "VITE_", | ||
client: { | ||
VITE_WEB_URL: z.string().url().default("https://app.follow.is"), | ||
VITE_API_URL: z.string(), | ||
VITE_DEV_PROXY: z.string().optional(), | ||
VITE_SENTRY_DSN: z.string().optional(), | ||
VITE_INBOXES_EMAIL: z.string().default("@follow.re"), | ||
VITE_FIREBASE_CONFIG: z.string().optional(), | ||
|
||
VITE_OPENPANEL_CLIENT_ID: z.string().optional(), | ||
VITE_OPENPANEL_API_URL: z.string().url().optional(), | ||
|
||
// For external, use api_url if you don't want to fill it in. | ||
VITE_EXTERNAL_PROD_API_URL: z.string().optional(), | ||
VITE_EXTERNAL_DEV_API_URL: z.string().optional(), | ||
VITE_EXTERNAL_API_URL: z.string().optional(), | ||
VITE_WEB_PROD_URL: z.string().optional(), | ||
VITE_WEB_DEV_URL: z.string().optional(), | ||
}, | ||
|
||
emptyStringAsUndefined: true, | ||
runtimeEnv: getRuntimeEnv() as any, | ||
|
||
skipValidation: "process" in globalThis ? process.env.VITEST === "true" : false, | ||
}) | ||
|
||
function metaEnvIsEmpty() { | ||
try { | ||
return Object.keys(import.meta.env || {}).length === 0 | ||
} catch { | ||
return true | ||
} | ||
export const envSchema = { | ||
VITE_WEB_URL: z.string().url().default("https://app.follow.is"), | ||
VITE_API_URL: z.string().default("https://api.follow.is"), | ||
VITE_DEV_PROXY: z.string().optional(), | ||
VITE_SENTRY_DSN: z.string().optional(), | ||
VITE_INBOXES_EMAIL: z.string().default("@follow.re"), | ||
VITE_FIREBASE_CONFIG: z.string().optional(), | ||
|
||
VITE_OPENPANEL_CLIENT_ID: z.string().optional(), | ||
VITE_OPENPANEL_API_URL: z.string().url().optional(), | ||
|
||
// For external, use api_url if you don't want to fill it in. | ||
VITE_EXTERNAL_PROD_API_URL: z.string().optional(), | ||
VITE_EXTERNAL_DEV_API_URL: z.string().optional(), | ||
VITE_EXTERNAL_API_URL: z.string().optional(), | ||
VITE_WEB_PROD_URL: z.string().optional(), | ||
VITE_WEB_DEV_URL: z.string().optional(), | ||
} | ||
|
||
function getRuntimeEnv() { | ||
try { | ||
if (metaEnvIsEmpty()) { | ||
return process.env | ||
} | ||
return injectExternalEnv(import.meta.env) | ||
} catch { | ||
return process.env | ||
} | ||
} | ||
|
||
declare const globalThis: any | ||
function injectExternalEnv<T>(originEnv: T): T { | ||
if (!("document" in globalThis)) { | ||
return originEnv | ||
} | ||
const prefix = "__followEnv" | ||
const env = globalThis[prefix] | ||
if (!env) { | ||
return originEnv | ||
} | ||
|
||
for (const key in env) { | ||
originEnv[key as keyof T] = env[key] | ||
} | ||
return originEnv | ||
} | ||
export const isDev = false | ||
export const env = z.object(envSchema).parse({}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.