[#1] Add default theme env variable
This commit is contained in:
@ -18,6 +18,8 @@ PRISMA_HIDE_UPDATE_MESSAGE=true
|
|||||||
FIRST_NAME=firstname
|
FIRST_NAME=firstname
|
||||||
LAST_NAME=lastname
|
LAST_NAME=lastname
|
||||||
|
|
||||||
|
DEFAULT_THEME=light
|
||||||
|
|
||||||
COUNTRY=US
|
COUNTRY=US
|
||||||
|
|
||||||
SMTP_HOST=smtp.example.com
|
SMTP_HOST=smtp.example.com
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
FIRST_NAME=firstname
|
FIRST_NAME=firstname
|
||||||
LAST_NAME=lastname
|
LAST_NAME=lastname
|
||||||
|
|
||||||
|
DEFAULT_THEME=light
|
||||||
|
|
||||||
COUNTRY=US
|
COUNTRY=US
|
||||||
|
|
||||||
SMTP_HOST=smtp.example.com
|
SMTP_HOST=smtp.example.com
|
||||||
|
@ -62,6 +62,7 @@ FROM api_build as web_build_with_prerender
|
|||||||
|
|
||||||
ARG FIRST_NAME
|
ARG FIRST_NAME
|
||||||
ARG LAST_NAME
|
ARG LAST_NAME
|
||||||
|
ARG DEFAULT_THEME
|
||||||
ARG API_ADDRESS_PROD
|
ARG API_ADDRESS_PROD
|
||||||
ARG API_ADDRESS_DEV
|
ARG API_ADDRESS_DEV
|
||||||
|
|
||||||
@ -74,6 +75,7 @@ FROM base as web_build
|
|||||||
|
|
||||||
ARG FIRST_NAME
|
ARG FIRST_NAME
|
||||||
ARG LAST_NAME
|
ARG LAST_NAME
|
||||||
|
ARG DEFAULT_THEME
|
||||||
ARG API_ADDRESS_PROD
|
ARG API_ADDRESS_PROD
|
||||||
ARG API_ADDRESS_DEV
|
ARG API_ADDRESS_DEV
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ services:
|
|||||||
- FIRST_NAME=first name # Your first name
|
- FIRST_NAME=first name # Your first name
|
||||||
- LAST_NAME=lastname # Your last name
|
- LAST_NAME=lastname # Your last name
|
||||||
- COUNTRY=US # ISO-3166-1 alpha-2 country code, https://en.wikipedia.org/wiki/ISO_3166-1#Codes
|
- COUNTRY=US # ISO-3166-1 alpha-2 country code, https://en.wikipedia.org/wiki/ISO_3166-1#Codes
|
||||||
|
- DEFAULT_THEME=light # 'light' or 'dark'
|
||||||
- SMTP_HOST=smtp.example.com
|
- SMTP_HOST=smtp.example.com
|
||||||
- SMTP_PORT=465
|
- SMTP_PORT=465
|
||||||
- SMTP_SECURE=true
|
- SMTP_SECURE=true
|
||||||
|
@ -9,6 +9,12 @@ import { createServer } from '@redwoodjs/api-server'
|
|||||||
|
|
||||||
import { logger } from 'src/lib/logger'
|
import { logger } from 'src/lib/logger'
|
||||||
import { handleTusUpload } from 'src/lib/tus'
|
import { handleTusUpload } from 'src/lib/tus'
|
||||||
|
|
||||||
|
enum Theme {
|
||||||
|
light = 'light',
|
||||||
|
dark = 'dark',
|
||||||
|
}
|
||||||
|
|
||||||
;(async () => {
|
;(async () => {
|
||||||
const { hasFlag } = await import('country-flag-icons')
|
const { hasFlag } = await import('country-flag-icons')
|
||||||
|
|
||||||
@ -17,6 +23,11 @@ import { handleTusUpload } from 'src/lib/tus'
|
|||||||
'Invalid COUNTRY environment variable, please select a valid ISO-3166-1 alpha-2 country code\n See https://en.wikipedia.org/wiki/ISO_3166-1#Codes'
|
'Invalid COUNTRY environment variable, please select a valid ISO-3166-1 alpha-2 country code\n See https://en.wikipedia.org/wiki/ISO_3166-1#Codes'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (!(process.env.DEFAULT_THEME.toLowerCase() in Theme))
|
||||||
|
throw new Error(
|
||||||
|
'Invalid DEFAULT_THEME environment variable, please select either light or dark'
|
||||||
|
)
|
||||||
|
|
||||||
const server = await createServer({
|
const server = await createServer({
|
||||||
logger,
|
logger,
|
||||||
configureApiServer: async (server) => {
|
configureApiServer: async (server) => {
|
||||||
|
@ -13,6 +13,7 @@ services:
|
|||||||
- FIRST_NAME=first name # Your first name
|
- FIRST_NAME=first name # Your first name
|
||||||
- LAST_NAME=lastname # Your last name
|
- LAST_NAME=lastname # Your last name
|
||||||
- COUNTRY=US # ISO-3166-1 alpha-2 country code, https://en.wikipedia.org/wiki/ISO_3166-1#Codes
|
- COUNTRY=US # ISO-3166-1 alpha-2 country code, https://en.wikipedia.org/wiki/ISO_3166-1#Codes
|
||||||
|
- DEFAULT_THEME=light # 'light' or 'dark'
|
||||||
- SMTP_HOST=smtp.example.com
|
- SMTP_HOST=smtp.example.com
|
||||||
- SMTP_PORT=465
|
- SMTP_PORT=465
|
||||||
- SMTP_SECURE=true
|
- SMTP_SECURE=true
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
title = "${FIRST_NAME} ${LAST_NAME}"
|
title = "${FIRST_NAME} ${LAST_NAME}"
|
||||||
port = 8910
|
port = 8910
|
||||||
apiUrl = "/api"
|
apiUrl = "/api"
|
||||||
includeEnvironmentVariables = ["FIRST_NAME", "LAST_NAME", "COUNTRY", "API_ADDRESS_PROD", "API_ADDRESS_DEV"]
|
includeEnvironmentVariables = ["FIRST_NAME", "LAST_NAME", "COUNTRY", "DEFAULT_THEME", "API_ADDRESS_PROD", "API_ADDRESS_DEV"]
|
||||||
[generate]
|
[generate]
|
||||||
tests = false
|
tests = false
|
||||||
stories = false
|
stories = false
|
||||||
|
@ -8,7 +8,10 @@ const DARK_THEME = 'dark'
|
|||||||
|
|
||||||
const ThemeToggle = () => {
|
const ThemeToggle = () => {
|
||||||
const [theme, setTheme] = useState(
|
const [theme, setTheme] = useState(
|
||||||
localStorage.getItem('theme') ?? LIGHT_THEME
|
localStorage.getItem('theme') ||
|
||||||
|
([LIGHT_THEME, DARK_THEME].includes(process.env.DEFAULT_THEME)
|
||||||
|
? process.env.DEFAULT_THEME
|
||||||
|
: LIGHT_THEME)
|
||||||
)
|
)
|
||||||
|
|
||||||
const handleToggle = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleToggle = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
@ -8,6 +8,11 @@ import App from 'src/App'
|
|||||||
* rather than replacing it.
|
* rather than replacing it.
|
||||||
* https://react.dev/reference/react-dom/client/hydrateRoot
|
* https://react.dev/reference/react-dom/client/hydrateRoot
|
||||||
*/
|
*/
|
||||||
|
enum Theme {
|
||||||
|
light = 'light',
|
||||||
|
dark = 'dark',
|
||||||
|
}
|
||||||
|
|
||||||
const redwoodAppElement = document.getElementById('redwood-app')
|
const redwoodAppElement = document.getElementById('redwood-app')
|
||||||
|
|
||||||
if (!redwoodAppElement)
|
if (!redwoodAppElement)
|
||||||
@ -21,6 +26,11 @@ if (!hasFlag(process.env.COUNTRY))
|
|||||||
'Invalid COUNTRY environment variable, please select a valid ISO-3166-1 alpha-2 country code\n See https://en.wikipedia.org/wiki/ISO_3166-1#Codes'
|
'Invalid COUNTRY environment variable, please select a valid ISO-3166-1 alpha-2 country code\n See https://en.wikipedia.org/wiki/ISO_3166-1#Codes'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (!(process.env.DEFAULT_THEME.toLowerCase() in Theme))
|
||||||
|
throw new Error(
|
||||||
|
'Invalid DEFAULT_THEME environment variable, please select either light or dark'
|
||||||
|
)
|
||||||
|
|
||||||
if (redwoodAppElement.children?.length > 0)
|
if (redwoodAppElement.children?.length > 0)
|
||||||
hydrateRoot(redwoodAppElement, <App />)
|
hydrateRoot(redwoodAppElement, <App />)
|
||||||
else {
|
else {
|
||||||
|
Reference in New Issue
Block a user