Skip to content

Instantly share code, notes, and snippets.

@wnqueiroz
Created April 23, 2024 17:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wnqueiroz/eb7beaf2bc92e126f8921bb0feb9f50c to your computer and use it in GitHub Desktop.
Save wnqueiroz/eb7beaf2bc92e126f8921bb0feb9f50c to your computer and use it in GitHub Desktop.
Next.js 12-factor App Support
# -------------------------- .docker/entrypoint.sh --------------------------
#!/bin/bash
DIR=".next"
find "${DIR}" -type f | while read -r file; do
for var in $(env | cut -d= -f1 | grep '^NEXT_PUBLIC'); do
PATTERN="\$${var}"
NEW_VALUE=$(eval echo "\$$var")
SED_COMMAND="s|${PATTERN}|${NEW_VALUE}|g"
sed -i "${SED_COMMAND}" "${file}"
done
done
HOSTNAME="0.0.0.0" yarn start
# -------------------------- Dockerfile --------------------------
CMD sh .docker/entrypoint.sh
# -------------------------- NEXT_PUBLIC_* envs usage --------------------------
const MY_API_KEY = process.env.NEXT_PUBLIC_MY_API_KEY || "$NEXT_PUBLIC_MY_API_KEY";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment