ajout app
This commit is contained in:
62
Voltaserve/idp/src/config/config.ts
Normal file
62
Voltaserve/idp/src/config/config.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { Config } from './types'
|
||||
|
||||
let config: Config
|
||||
|
||||
export function getConfig(): Config {
|
||||
if (!config) {
|
||||
config = new Config()
|
||||
config.port = parseInt(process.env.PORT)
|
||||
readURLs(config)
|
||||
readToken(config)
|
||||
readCORS(config)
|
||||
readSearch(config)
|
||||
readSMTP(config)
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
export function readURLs(config: Config) {
|
||||
config.publicUIURL = process.env.PUBLIC_UI_URL
|
||||
config.databaseURL = process.env.POSTGRES_URL
|
||||
}
|
||||
|
||||
export function readToken(config: Config) {
|
||||
config.token.jwtSigningKey = process.env.TOKEN_JWT_SIGNING_KEY
|
||||
config.token.audience = process.env.TOKEN_AUDIENCE
|
||||
config.token.issuer = process.env.TOKEN_ISSUER
|
||||
if (process.env.TOKEN_ACCESS_TOKEN_LIFETIME) {
|
||||
config.token.accessTokenLifetime = parseInt(
|
||||
process.env.TOKEN_ACCESS_TOKEN_LIFETIME
|
||||
)
|
||||
}
|
||||
if (process.env.TOKEN_REFRESH_TOKEN_LIFETIME) {
|
||||
config.token.refreshTokenLifetime = parseInt(
|
||||
process.env.TOKEN_REFRESH_TOKEN_LIFETIME
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export function readCORS(config: Config) {
|
||||
if (process.env.CORS_ORIGINS) {
|
||||
config.corsOrigins = process.env.CORS_ORIGINS.split(',')
|
||||
config.corsOrigins.forEach((e) => e.trim())
|
||||
}
|
||||
}
|
||||
|
||||
export function readSearch(config: Config) {
|
||||
config.search.url = process.env.SEARCH_URL
|
||||
}
|
||||
|
||||
export function readSMTP(config: Config) {
|
||||
config.smtp.host = process.env.SMTP_HOST
|
||||
if (process.env.SMTP_PORT) {
|
||||
config.smtp.port = parseInt(process.env.SMTP_PORT)
|
||||
}
|
||||
if (process.env.SMTP_SECURE) {
|
||||
config.smtp.secure = process.env.SMTP_SECURE === 'true'
|
||||
}
|
||||
config.smtp.username = process.env.SMTP_USERNAME
|
||||
config.smtp.password = process.env.SMTP_PASSWORD
|
||||
config.smtp.senderAddress = process.env.SMTP_SENDER_ADDRESS
|
||||
config.smtp.senderName = process.env.SMTP_SENDER_NAME
|
||||
}
|
41
Voltaserve/idp/src/config/types.ts
Normal file
41
Voltaserve/idp/src/config/types.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
export class Config {
|
||||
port: number
|
||||
publicUIURL: string
|
||||
databaseURL: string
|
||||
token: TokenConfig
|
||||
corsOrigins: string[]
|
||||
search: SearchConfig
|
||||
smtp: SMTPConfig
|
||||
|
||||
constructor() {
|
||||
this.token = new TokenConfig()
|
||||
this.search = new SearchConfig()
|
||||
this.smtp = new SMTPConfig()
|
||||
}
|
||||
}
|
||||
|
||||
export class DatabaseConfig {
|
||||
url: string
|
||||
}
|
||||
|
||||
export class TokenConfig {
|
||||
jwtSigningKey: string
|
||||
audience: string
|
||||
issuer: string
|
||||
accessTokenLifetime: number
|
||||
refreshTokenLifetime: number
|
||||
}
|
||||
|
||||
export class SearchConfig {
|
||||
url: string
|
||||
}
|
||||
|
||||
export class SMTPConfig {
|
||||
host: string
|
||||
port: number
|
||||
secure: boolean
|
||||
username?: string
|
||||
password?: string
|
||||
senderAddress: string
|
||||
senderName: string
|
||||
}
|
Reference in New Issue
Block a user