mirror of
https://github.com/sasjs/server.git
synced 2025-12-11 03:34:35 +00:00
feat(env): added new env variable LOG_FORMAT_MORGAN
This commit is contained in:
@@ -125,6 +125,10 @@ HELMET_COEP=
|
|||||||
# }
|
# }
|
||||||
HELMET_CSP_CONFIG_PATH=./csp.config.json
|
HELMET_CSP_CONFIG_PATH=./csp.config.json
|
||||||
|
|
||||||
|
# LOG_FORMAT_MORGAN options: [combined|common|dev|short|tiny] default: `common`
|
||||||
|
# Docs: https://www.npmjs.com/package/morgan#predefined-formats
|
||||||
|
LOG_FORMAT_MORGAN=
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Persisting the Session
|
## Persisting the Session
|
||||||
|
|||||||
@@ -19,3 +19,5 @@ DB_CONNECT=mongodb+srv://<DB_USERNAME>:<DB_PASSWORD>@<CLUSTER>/<DB_NAME>?retryWr
|
|||||||
|
|
||||||
SAS_PATH=/opt/sas/sas9/SASHome/SASFoundation/9.4/sas
|
SAS_PATH=/opt/sas/sas9/SASHome/SASFoundation/9.4/sas
|
||||||
SASJS_ROOT=./sasjs_root
|
SASJS_ROOT=./sasjs_root
|
||||||
|
|
||||||
|
LOG_FORMAT_MORGAN=common
|
||||||
@@ -37,10 +37,18 @@ if (verifyEnvVariables()) {
|
|||||||
const app = express()
|
const app = express()
|
||||||
|
|
||||||
app.use(cookieParser())
|
app.use(cookieParser())
|
||||||
app.use(morgan('tiny'))
|
|
||||||
|
|
||||||
const { MODE, CORS, WHITELIST, PROTOCOL, HELMET_CSP_CONFIG_PATH, HELMET_COEP } =
|
const {
|
||||||
process.env
|
MODE,
|
||||||
|
CORS,
|
||||||
|
WHITELIST,
|
||||||
|
PROTOCOL,
|
||||||
|
HELMET_CSP_CONFIG_PATH,
|
||||||
|
HELMET_COEP,
|
||||||
|
LOG_FORMAT_MORGAN
|
||||||
|
} = process.env
|
||||||
|
|
||||||
|
app.use(morgan(LOG_FORMAT_MORGAN as string))
|
||||||
|
|
||||||
export const cookieOptions = {
|
export const cookieOptions = {
|
||||||
secure: PROTOCOL === ProtocolType.HTTPS,
|
secure: PROTOCOL === ProtocolType.HTTPS,
|
||||||
|
|||||||
@@ -18,6 +18,14 @@ export enum HelmetCoepType {
|
|||||||
FALSE = 'false'
|
FALSE = 'false'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum LOG_FORMAT_MORGANType {
|
||||||
|
Combined = 'combined',
|
||||||
|
Common = 'common',
|
||||||
|
Dev = 'dev',
|
||||||
|
Short = 'short',
|
||||||
|
tiny = 'tiny'
|
||||||
|
}
|
||||||
|
|
||||||
export enum ReturnCode {
|
export enum ReturnCode {
|
||||||
Success,
|
Success,
|
||||||
InvalidEnv
|
InvalidEnv
|
||||||
@@ -36,6 +44,8 @@ export const verifyEnvVariables = (): ReturnCode => {
|
|||||||
|
|
||||||
errors.push(...verifyHELMET_COEP())
|
errors.push(...verifyHELMET_COEP())
|
||||||
|
|
||||||
|
errors.push(...verifyLOG_FORMAT_MORGAN())
|
||||||
|
|
||||||
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')}`
|
||||||
@@ -173,9 +183,29 @@ const verifyHELMET_COEP = (): string[] => {
|
|||||||
return errors
|
return errors
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULTS = {
|
const verifyLOG_FORMAT_MORGAN = (): string[] => {
|
||||||
MODE: 'desktop',
|
const errors: string[] = []
|
||||||
PROTOCOL: 'http',
|
const { LOG_FORMAT_MORGAN } = process.env
|
||||||
PORT: '5000',
|
|
||||||
HELMET_COEP: 'true'
|
if (LOG_FORMAT_MORGAN) {
|
||||||
|
const logFormatMorganTypes = Object.values(LOG_FORMAT_MORGANType)
|
||||||
|
if (
|
||||||
|
!logFormatMorganTypes.includes(LOG_FORMAT_MORGAN as LOG_FORMAT_MORGANType)
|
||||||
|
)
|
||||||
|
errors.push(
|
||||||
|
`- LOG_FORMAT_MORGAN '${LOG_FORMAT_MORGAN}'\n - valid options ${logFormatMorganTypes}`
|
||||||
|
)
|
||||||
|
LOG_FORMAT_MORGAN
|
||||||
|
} else {
|
||||||
|
process.env.LOG_FORMAT_MORGAN = DEFAULTS.LOG_FORMAT_MORGAN
|
||||||
|
}
|
||||||
|
return errors
|
||||||
|
}
|
||||||
|
|
||||||
|
const DEFAULTS = {
|
||||||
|
MODE: ModeType.Desktop,
|
||||||
|
PROTOCOL: ProtocolType.HTTP,
|
||||||
|
PORT: '5000',
|
||||||
|
HELMET_COEP: HelmetCoepType.TRUE,
|
||||||
|
LOG_FORMAT_MORGAN: LOG_FORMAT_MORGANType.Common
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user