-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dbd0067
commit a52df22
Showing
21 changed files
with
144 additions
and
81 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
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
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,25 +1,24 @@ | ||
import { useMemo } from 'react' | ||
|
||
import { NextConfig } from 'next' | ||
import getConfig from 'next/config' | ||
|
||
import { publicRuntimeConfigSchema } from '../schemas/public-runtime-config-schema' | ||
|
||
export const usePublicRuntimeConfig = () => { | ||
const config = getConfig() as NextConfig | ||
const config = getConfig() | ||
|
||
const { ADOBE_ANALYTICS_SCRIPT_SRC, ANALYTICS_BEACON_DELAY, APP_BASE_URI, ENVIRONMENT, LOGGING_LEVEL } = | ||
config?.publicRuntimeConfig ?? {} | ||
|
||
return useMemo( | ||
() => | ||
publicRuntimeConfigSchema.validateSync({ | ||
NEXT_PUBLIC_ADOBE_ANALYTICS_SCRIPT_SRC: config.publicRuntimeConfig?.NEXT_PUBLIC_ADOBE_ANALYTICS_SCRIPT_SRC, | ||
NEXT_PUBLIC_ANALYTICS_BEACON_DELAY: config.publicRuntimeConfig?.NEXT_PUBLIC_ANALYTICS_BEACON_DELAY, | ||
NEXT_PUBLIC_APP_BASE_URI: config.publicRuntimeConfig?.NEXT_PUBLIC_APP_BASE_URI, | ||
NEXT_PUBLIC_ENVIRONMENT: config.publicRuntimeConfig?.NEXT_PUBLIC_ENVIRONMENT, | ||
ADOBE_ANALYTICS_SCRIPT_SRC, | ||
ANALYTICS_BEACON_DELAY, | ||
APP_BASE_URI, | ||
ENVIRONMENT, | ||
LOGGING_LEVEL, | ||
}), | ||
[ | ||
config.publicRuntimeConfig?.NEXT_PUBLIC_ADOBE_ANALYTICS_SCRIPT_SRC, | ||
config.publicRuntimeConfig?.NEXT_PUBLIC_ANALYTICS_BEACON_DELAY, | ||
config.publicRuntimeConfig?.NEXT_PUBLIC_APP_BASE_URI, | ||
config.publicRuntimeConfig?.NEXT_PUBLIC_ENVIRONMENT, | ||
] | ||
[ADOBE_ANALYTICS_SCRIPT_SRC, ANALYTICS_BEACON_DELAY, APP_BASE_URI, ENVIRONMENT, LOGGING_LEVEL], | ||
) | ||
} |
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,17 +1,29 @@ | ||
import { LevelWithSilent } from 'pino' | ||
import * as yup from 'yup' | ||
|
||
export const levelsWithSilent: ReadonlyArray<LevelWithSilent> = [ | ||
'debug', | ||
'error', | ||
'fatal', | ||
'info', | ||
'silent', | ||
'trace', | ||
'warn', | ||
] | ||
|
||
export const publicRuntimeConfigSchema = yup.object({ | ||
NEXT_PUBLIC_ADOBE_ANALYTICS_SCRIPT_SRC: yup | ||
.string() | ||
.url('Environment variable NEXT_PUBLIC_ADOBE_ANALYTICS_SCRIPT_SRC must be a valid URL'), | ||
NEXT_PUBLIC_ANALYTICS_BEACON_DELAY: yup | ||
ADOBE_ANALYTICS_SCRIPT_SRC: yup.string().url('Env. variable ${path} must be a valid URL'), | ||
ANALYTICS_BEACON_DELAY: yup | ||
.number() | ||
.integer('Environment variable NEXT_PUBLIC_ANALYTICS_BEACON_DELAY must be an integer') | ||
.min(0, 'Environment variable NEXT_PUBLIC_ANALYTICS_BEACON_DELAY must be greater than or equal to 0') | ||
.integer('Env. variable ${path} must be an integer') | ||
.min(0, 'Env. variable ${path} must be greater than or equal to ${min}') | ||
.default(() => 250), | ||
NEXT_PUBLIC_APP_BASE_URI: yup | ||
APP_BASE_URI: yup | ||
.string() | ||
.required('Env. variable ${path} is required') | ||
.url('Env. variable ${path} must be a valid URL'), | ||
ENVIRONMENT: yup.string(), | ||
LOGGING_LEVEL: yup | ||
.string() | ||
.required('Environment variable NEXT_PUBLIC_APP_BASE_URI is required') | ||
.url('Environment variable NEXT_PUBLIC_APP_BASE_URI must be a valid URL'), | ||
NEXT_PUBLIC_ENVIRONMENT: yup.string(), | ||
.oneOf(levelsWithSilent, 'Env. variable ${path} must be one of the following values: ${values}'), | ||
}) |
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,7 +1,14 @@ | ||
const logLevelData = { | ||
'*': process.env.LOGGING_LEVEL, | ||
import getConfig from 'next/config' | ||
|
||
export const getLoggingLevelConfig = (): string | undefined => { | ||
// middleware can only read from process.env | ||
if (process.env.LOGGING_LEVEL) return process.env.LOGGING_LEVEL | ||
return getConfig()?.publicRuntimeConfig?.LOGGING_LEVEL | ||
} | ||
|
||
export const logLevelData = { | ||
'*': getLoggingLevelConfig(), | ||
// 'middleware': '' | ||
// 'home': 'info', | ||
// 'app': 'debug', | ||
} | ||
export default logLevelData |
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
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
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.