generated from sripwoud/ts-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: check definition of config variables at runtime (#12)
* feat: check definition of config variables at runtime * ci(server): fix Dockerfile
- Loading branch information
Showing
24 changed files
with
124 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
use asdf | ||
|
||
# db | ||
export SUPABASE_URL= | ||
export SUPABASE_ANON_KEY= | ||
|
||
export LOCAL_SUPABASE_URL= | ||
export LOCAL_SUPABASE_ANON_KEY= | ||
# server | ||
export ALCHEMY_API_KEY= | ||
|
||
# client | ||
export NEXT_PUBLIC_SERVER_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 |
---|---|---|
|
@@ -5,3 +5,4 @@ lcov.info | |
.envrc | ||
**/*.bak | ||
repopack-output.txt | ||
*.tsbuildinfo |
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,16 @@ | ||
import { isEnvVarDefined, sharedConfig, type SharedConfigI } from 'config' | ||
|
||
interface ClientConfigI { | ||
serverUrl: string | ||
} | ||
|
||
// @ts-expect-error 4111 | ||
const serverUrl = process.env.NEXT_PUBLIC_SERVER_URL ?? '' | ||
isEnvVarDefined(serverUrl, 'NEXT_PUBLIC_SERVER_URL') | ||
|
||
const clientConfig: SharedConfigI & ClientConfigI = { | ||
...sharedConfig, | ||
serverUrl, | ||
} | ||
|
||
export default clientConfig |
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
Empty file.
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
# | ||
|
||
app = 'rideau' | ||
primary_region = 'ams' | ||
primary_region = 'fra' | ||
|
||
[build] | ||
|
||
|
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
File renamed without changes.
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 |
---|---|---|
@@ -1,18 +1,16 @@ | ||
import { NestFactory } from '@nestjs/core' | ||
import { AppModule } from 'server/app.module' | ||
import config from 'server/l/config' | ||
import { TrpcRouter } from 'server/trpc/trpc.router' | ||
|
||
// TODO: make port configurable | ||
const PORT = 3001 | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule) | ||
app.enableCors() | ||
|
||
const trpc = app.get(TrpcRouter) | ||
trpc.applyMiddleware(app) | ||
|
||
await app.listen(PORT) | ||
await app.listen(config.port) | ||
} | ||
|
||
bootstrap() |
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,19 @@ | ||
import { getEnvVar, sharedConfig, type SharedConfigI } from 'config' | ||
|
||
interface ServerConfigI { | ||
alchemyApiKey: string | ||
port: number | ||
supabase: { anonKey: string; url: string } | ||
} | ||
|
||
const serverConfig: ServerConfigI & SharedConfigI = { | ||
...sharedConfig, | ||
alchemyApiKey: getEnvVar('ALCHEMY_API_KEY'), | ||
port: 3001, | ||
supabase: { | ||
anonKey: getEnvVar('SUPABASE_ANON_KEY'), | ||
url: getEnvVar('SUPABASE_URL'), | ||
}, | ||
} | ||
|
||
export default serverConfig |
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,8 +1,8 @@ | ||
import { Injectable } from '@nestjs/common' | ||
import { createClient } from '@supabase/supabase-js' | ||
import config from 'server/l/config' | ||
|
||
@Injectable() | ||
export class SupabaseService { | ||
// biome-ignore lint/style/noNonNullAssertion: FIXME | ||
supabase = createClient(process.env['SUPABASE_URL']!, process.env['SUPABASE_ANON_KEY']!) | ||
supabase = createClient(config.supabase.url, config.supabase.anonKey) | ||
} |
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,3 @@ | ||
export { default as sharedConfig } from 'config/shared' | ||
export type { SharedConfigI } from 'config/types' | ||
export { getEnvVar, isEnvVarDefined } from 'config/utils' |
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,8 @@ | ||
import type { SharedConfigI } from 'config/types' | ||
|
||
const config: SharedConfigI = { | ||
appName: 'rideau', | ||
alchemyProxyEndpoint: 'alchemy', | ||
} | ||
|
||
export default config |
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,9 @@ | ||
export enum Env { | ||
DEVELOPMENT = 'DEVELOPMENT', | ||
PRODUCTION = 'PRODUCTION', | ||
} | ||
|
||
export interface SharedConfigI { | ||
appName: string | ||
alchemyProxyEndpoint: string | ||
} |
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,15 @@ | ||
export function isEnvVarDefined(name: string, value: unknown) { | ||
if (value === '') throw new Error(`Missing environment variable ${name}`) | ||
} | ||
|
||
/** | ||
* DO NOT USE TO CHECK ENVIRONMENT VARIABLES USED CLIENT SIDE IN NEXTJS | ||
* NextJS inline client-side environment variables to make them accessible by the browser | ||
* But dynamic access to environment variables is not inlined | ||
* {@link https://nextjs.org/docs/basic-features/environment-variables#loading-environment-variables} | ||
*/ | ||
export function getEnvVar<T extends string>(name: T) { | ||
const value = process.env[name] ?? '' | ||
isEnvVarDefined(name, value) | ||
return value | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
# bun ./bun.lockb --hash: FBCD7AF1034998C3-81b4157dbd3990ad-191C33EDCCA73559-4e08cd2f2985cf67 | ||
# bun ./bun.lockb --hash: A7975FC6190E722F-cfa64adf9c1f0f32-47EE7DF9252DAE90-f880c665a4692a26 | ||
|
||
|
||
"@aa-sdk/core@^4.0.0-beta.9": | ||
|
@@ -3862,13 +3862,20 @@ | |
dependencies: | ||
undici-types "~5.26.4" | ||
|
||
"@types/node@*", "@types/node@^20", "@types/node@^20.3.1": | ||
"@types/node@*", "@types/node@^20": | ||
version "20.16.10" | ||
resolved "https://registry.npmjs.org/@types/node/-/node-20.16.10.tgz" | ||
integrity sha512-vQUKgWTjEIRFCvK6CyriPH3MZYiYlNy0fKiEYHWbcoWLEgs4opurGGKlebrTLqdSMIbXImH6XExNiIyNUv3WpA== | ||
dependencies: | ||
undici-types "~6.19.2" | ||
|
||
"@types/node@^22.7.5": | ||
version "22.7.5" | ||
resolved "https://registry.npmjs.org/@types/node/-/node-22.7.5.tgz" | ||
integrity sha512-jML7s2NAzMWc//QSJ1a3prpk78cOPchGvXJsC3C6R6PSMoooztvRVQEz89gmBTBY1SPMaqo5teB4uNHPdetShQ== | ||
dependencies: | ||
undici-types "~6.19.2" | ||
|
||
"@types/node-forge@^1.3.0": | ||
version "1.3.11" | ||
resolved "https://registry.npmjs.org/@types/node-forge/-/node-forge-1.3.11.tgz" | ||
|
@@ -10173,7 +10180,7 @@ [email protected], serve-static@^1.13.1: | |
"@nestjs/testing" "^10.0.0" | ||
"@types/express" "^5.0.0" | ||
"@types/jest" "^29.5.2" | ||
"@types/node" "^20.3.1" | ||
"@types/node" "^22.7.5" | ||
"@types/supertest" "^6.0.0" | ||
eslint "^8.42.0" | ||
jest "^29.5.0" | ||
|