-
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.
Merge pull request #176 from lil-lab/recnet-api/add-config-service
[recnet-api] Add config service
- Loading branch information
Showing
6 changed files
with
196 additions
and
50 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 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,18 @@ | ||
import { registerAs } from "@nestjs/config"; | ||
|
||
import { parseEnv } from "./env.schema"; | ||
|
||
const parsedEnv = parseEnv(process.env); | ||
|
||
export const DBConfig = registerAs("db", () => ({ | ||
host: parsedEnv.RDS_HOSTNAME, | ||
port: parsedEnv.RDS_PORT, | ||
database: parsedEnv.RDS_DB_NAME, | ||
username: parsedEnv.RDS_USERNAME, | ||
password: parsedEnv.RDS_PASSWORD, | ||
})); | ||
|
||
export const PrismaConfig = registerAs("prisma", () => ({ | ||
schema: parsedEnv.PRISMA_SCHEMA, | ||
migrate: parsedEnv.DB_MIGRATE, | ||
})); |
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,22 @@ | ||
import { z } from "zod"; | ||
|
||
const nodeEnv = z.enum(["development", "production", "local", "test"]); | ||
|
||
export const EnvSchema = z.object({ | ||
PORT: z.coerce.number().optional().default(3000), | ||
NODE_ENV: nodeEnv.default("development"), | ||
// db config | ||
RDS_HOSTNAME: z.string().optional().default("localhost"), | ||
RDS_PORT: z.coerce.number().optional().default(5432), | ||
RDS_DB_NAME: z.string(), | ||
RDS_USERNAME: z.string(), | ||
RDS_PASSWORD: z.string(), | ||
// prisma config | ||
PRISMA_SCHEMA: z.string().optional().default("prisma/schema.prisma"), | ||
DB_MIGRATE: z.coerce.boolean().optional().default(false), | ||
}); | ||
|
||
export const parseEnv = (env: Record<string, string>) => { | ||
const parsedEnv = EnvSchema.parse(env); | ||
return parsedEnv; | ||
}; |
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
Oops, something went wrong.