-
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.
Добавит схему конфигурации с помощью пакета convict
- Loading branch information
AdonaiJehosua
committed
Aug 24, 2024
1 parent
00f20fb
commit 6449897
Showing
7 changed files
with
176 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export interface Config { | ||
get(key: string): string | undefined; | ||
export interface Config<U> { | ||
get<T extends keyof U>(key: T): U[T]; | ||
} |
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,2 +1,3 @@ | ||
export * from './rest.config.js'; | ||
export * from './config.interface.js'; | ||
export * from './rest.schema.js'; |
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,32 @@ | ||
import convict from 'convict'; | ||
import validator from 'convict-format-with-validator'; | ||
|
||
convict.addFormats(validator); | ||
|
||
|
||
export type RestSchema = { | ||
PORT: number; | ||
SALT: string; | ||
DB_HOST: string; | ||
} | ||
|
||
export const configRestSchema = convict<RestSchema>({ | ||
PORT: { | ||
doc: 'Port for incoming connections', | ||
format: 'port', | ||
env: 'PORT', | ||
default: 4000 | ||
}, | ||
SALT: { | ||
doc: 'Salt for password hash', | ||
format: String, | ||
env: 'SALT', | ||
default: null | ||
}, | ||
DB_HOST: { | ||
doc: 'IP address of the database server (MongoDB)', | ||
format: 'ipaddress', | ||
env: 'DB_HOST', | ||
default: '127.0.0.1' | ||
}, | ||
}); |