Skip to content

Commit 24dca58

Browse files
tnagorrasamshara
authored andcommitted
Support alpha-* format for environments
1 parent 5c7ab88 commit 24dca58

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

app/env.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ import { defineConfig, Schema } from '@julr/vite-plugin-validate-env';
22

33
export default defineConfig({
44
APP_TITLE: Schema.string(),
5-
APP_ENVIRONMENT: Schema.enum(['development', 'testing', 'staging', 'production'] as const),
5+
APP_ENVIRONMENT: (key, value) => {
6+
const regex = /^production|staging|testing|alpha-\d+|development$/;
7+
const valid = !!value && (value.match(regex) !== null);
8+
if (!valid) {
9+
throw new Error(`Value for environment variable "${key}" must match regex "${regex}", instead received "${value}"`);
10+
}
11+
return value as ('production' | 'staging' | 'testing' | `alpha-${number}` | 'development');
12+
},
613
APP_API_ENDPOINT: Schema.string({ format: 'url', protocol: true, tld: false }),
714
APP_ADMIN_URL: Schema.string.optional({ format: 'url', protocol: true }),
815
APP_SHOW_ENV_BANNER: Schema.boolean.optional(),

app/src/views/RootLayout/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,9 @@ export function Component() {
352352
],
353353
);
354354

355-
const environmentTexts = {
355+
const environmentTexts: {
356+
[key in typeof environment]?: string;
357+
} = {
356358
production: strings.environmentTextProduction,
357359
development: strings.environmentTextDevelopment,
358360
staging: strings.environmentTextStaging,
@@ -378,7 +380,8 @@ export function Component() {
378380
<AlertContainer />
379381
{environment !== 'production' && (
380382
<div className={styles.banner}>
381-
{environmentTexts[environment]}
383+
{/* NOTE: We are not translating alpha server names */}
384+
{environmentTexts[environment] ?? environment}
382385
</div>
383386
)}
384387
</div>

0 commit comments

Comments
 (0)