-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(backend): configure environment variables
- Loading branch information
1 parent
3423798
commit 7d6b597
Showing
8 changed files
with
105 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
NODE_ENV=development | ||
APP_VERSION=1.0.0 | ||
HOST=http:https://localhost | ||
PORT=7501 | ||
ENABLE_INTROSPECTION=true | ||
DATABASE_URL="mysql:https://root:@127.0.0.1:3311/snipcode" | ||
ADMIN_PASSWORD=nwHSvXuQxjey43Bp | ||
CONVERTKIT_API_KEY=convertKitApiKey | ||
CONVERTKIT_FORM_ID=formId | ||
CONVERTKIT_TAG_ID=tagId | ||
REQUEST_TIMEOUT=30000 | ||
GITHUB_CLIENT_ID=<github_client_id_here> | ||
GITHUB_CLIENT_SECRET=<github_client_secret_here> | ||
WEB_APP_URL=http:https://localhost:7500 | ||
WEB_AUTH_SUCCESS_URL=http:https://localhost:7500/auth/success | ||
WEB_AUTH_ERROR_URL=http:https://localhost:7500/auth/error | ||
SESSION_LIFETIME=90# 90 days | ||
SENTRY_DSN= | ||
SENTRY_ENABLED=false | ||
SNIPPET_RENDERER_URL=http:https://localhost:3000/dev |
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,11 +1,20 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ConfigModule } from '@nestjs/config'; | ||
|
||
import { AppController } from './app.controller'; | ||
import { AppService } from './app.service'; | ||
import appConfig, { validate } from './configs/environment'; | ||
|
||
@Module({ | ||
controllers: [AppController], | ||
imports: [], | ||
imports: [ | ||
ConfigModule.forRoot({ | ||
envFilePath: ['.env', '.env.test'], | ||
isGlobal: true, | ||
load: [appConfig], | ||
validate, | ||
}), | ||
], | ||
providers: [AppService], | ||
}) | ||
export class AppModule {} |
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,26 @@ | ||
import { registerAs } from '@nestjs/config'; | ||
import { z } from 'zod'; | ||
|
||
export default registerAs('app', () => ({ | ||
env: process.env.NODE_ENV, | ||
host: process.env.HOST, | ||
port: parseInt(process.env.PORT ?? '7501', 10), | ||
})); | ||
|
||
const EnvironmentVariablesSchema = z.object({ | ||
HOST: z.string(), | ||
NODE_ENV: z.union([z.literal('development'), z.literal('production'), z.literal('test')]), | ||
PORT: z.number({ coerce: true }).min(7000).max(8000), | ||
}); | ||
|
||
export type EnvironmentVariables = z.infer<typeof EnvironmentVariablesSchema>; | ||
|
||
export const validate = (config: Record<string, unknown>): EnvironmentVariables => { | ||
const result = EnvironmentVariablesSchema.safeParse(config); | ||
|
||
if (!result.success) { | ||
throw new Error(JSON.stringify(result.error.format(), null, 2)); | ||
} | ||
|
||
return result.data; | ||
}; |
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,11 +1,23 @@ | ||
import { Logger } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { NestFactory } from '@nestjs/core'; | ||
|
||
import { AppModule } from './app.module'; | ||
import { EnvironmentVariables } from './types/common'; | ||
|
||
const bootstrap = async () => { | ||
const app = await NestFactory.create(AppModule); | ||
|
||
await app.listen(3000); | ||
const configService = app.get(ConfigService<EnvironmentVariables, true>); | ||
const logger = new Logger('NestApplication'); | ||
|
||
const port = configService.get<number>('PORT'); | ||
const host = configService.get<string>('HOST'); | ||
|
||
await app.listen(port, () => { | ||
logger.log(`Server ready at ${host}:${port}`); | ||
// logger.log(`Server ready at ${host}:${port}${graphqlServer.graphqlPath}`); | ||
}); | ||
}; | ||
|
||
void 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 @@ | ||
export type { EnvironmentVariables } from '../configs/environment'; |
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