mirror of
https://github.com/sasjs/server.git
synced 2025-12-11 19:44:35 +00:00
feat: validate sasjs_runtimes env var
This commit is contained in:
@@ -26,6 +26,11 @@ export enum LOG_FORMAT_MORGANType {
|
|||||||
tiny = 'tiny'
|
tiny = 'tiny'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum SASJSRunTimes {
|
||||||
|
SAS = 'sas',
|
||||||
|
JS = 'js'
|
||||||
|
}
|
||||||
|
|
||||||
export enum ReturnCode {
|
export enum ReturnCode {
|
||||||
Success,
|
Success,
|
||||||
InvalidEnv
|
InvalidEnv
|
||||||
@@ -46,6 +51,8 @@ export const verifyEnvVariables = (): ReturnCode => {
|
|||||||
|
|
||||||
errors.push(...verifyLOG_FORMAT_MORGAN())
|
errors.push(...verifyLOG_FORMAT_MORGAN())
|
||||||
|
|
||||||
|
errors.push(...verifySASJSRunTimes())
|
||||||
|
|
||||||
if (errors.length) {
|
if (errors.length) {
|
||||||
process.logger?.error(
|
process.logger?.error(
|
||||||
`Invalid environment variable(s) provided: \n${errors.join('\n')}`
|
`Invalid environment variable(s) provided: \n${errors.join('\n')}`
|
||||||
@@ -202,10 +209,35 @@ const verifyLOG_FORMAT_MORGAN = (): string[] => {
|
|||||||
return errors
|
return errors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const verifySASJSRunTimes = (): string[] => {
|
||||||
|
const errors: string[] = []
|
||||||
|
const { SASJS_RUNTIMES } = process.env
|
||||||
|
|
||||||
|
if (SASJS_RUNTIMES) {
|
||||||
|
const runTimes = SASJS_RUNTIMES.split(',').map((runTime) =>
|
||||||
|
runTime.toLowerCase()
|
||||||
|
)
|
||||||
|
|
||||||
|
const possibleRunTimes = Object.values(SASJSRunTimes)
|
||||||
|
|
||||||
|
runTimes.forEach((runTime) => {
|
||||||
|
if (!possibleRunTimes.includes(runTime as SASJSRunTimes)) {
|
||||||
|
errors.push(
|
||||||
|
`- Invalid '${runTime}' runtime\n - valid options ${possibleRunTimes}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
process.env.SASJS_RUNTIMES = DEFAULTS.SASJS_RUNTIMES
|
||||||
|
}
|
||||||
|
return errors
|
||||||
|
}
|
||||||
|
|
||||||
const DEFAULTS = {
|
const DEFAULTS = {
|
||||||
MODE: ModeType.Desktop,
|
MODE: ModeType.Desktop,
|
||||||
PROTOCOL: ProtocolType.HTTP,
|
PROTOCOL: ProtocolType.HTTP,
|
||||||
PORT: '5000',
|
PORT: '5000',
|
||||||
HELMET_COEP: HelmetCoepType.TRUE,
|
HELMET_COEP: HelmetCoepType.TRUE,
|
||||||
LOG_FORMAT_MORGAN: LOG_FORMAT_MORGANType.Common
|
LOG_FORMAT_MORGAN: LOG_FORMAT_MORGANType.Common,
|
||||||
|
SASJS_RUNTIMES: SASJSRunTimes.SAS
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user