You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm building a standalone app deployed via a Docker image to various environments. The Docker image is built using a Jenkins pipeline, which doesn't handle environment-specific variables.
At build time, the next.config.js file is serialised into a server.js file and also copied into required-server-files.json. However, this hardcodes certain configurations, including assetPrefix, making it environment-agnostic. To address this, I created a script that modifies server.js and required-server-files.json using sed to set the correct assetPrefix for each environment before starting the server.
The problem: In my CI environment, some _next/static files load with the correct assetPrefix, but others are missing it, resulting in 404 errors.
Has anyone encountered this issue or found a reliable solution?
Additional information
# This is my `docker/start.sh` script
SERVER_JS_SCRIPT="server.js"
REQUIRED_SERVER_FILES=".next/required-server-files.json"if [ !-f$SERVER_JS_SCRIPT ];thenexport$(grep -v '^#' .env)echo"server.js not found, running nextjs from standalone output"
SERVER_JS_SCRIPT="./.next/standalone/server.js"
REQUIRED_SERVER_FILES="./.next/standalone/.next/required-server-files.json"fi# Replace assetPrefix in server.js and required-server-files.json
ASSETS_PREFIX_SEARCH='"assetPrefix":""'
ASSETS_PREFIX_REPLACE="\"assetPrefix\":\"$NEXT_PUBLIC_BASE_PATH\""echo"replacing assetPrefix with $ASSETS_PREFIX_REPLACE..."
sed -i -e "s;$ASSETS_PREFIX_SEARCH;$ASSETS_PREFIX_REPLACE;"$SERVER_JS_SCRIPT
sed -i -e "s;$ASSETS_PREFIX_SEARCH;$ASSETS_PREFIX_REPLACE;"$REQUIRED_SERVER_FILES
PORT=$NEXT_PUBLIC_NODE_PORT HOSTNAME=$LOCAL_ADDRESS node $SERVER_JS_SCRIPT
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I'm building a standalone app deployed via a Docker image to various environments. The Docker image is built using a Jenkins pipeline, which doesn't handle environment-specific variables.
At build time, the
next.config.jsfile is serialised into aserver.jsfile and also copied intorequired-server-files.json. However, this hardcodes certain configurations, includingassetPrefix, making it environment-agnostic. To address this, I created a script that modifiesserver.jsandrequired-server-files.jsonusing sed to set the correct assetPrefix for each environment before starting the server.The problem: In my CI environment, some _next/static files load with the correct assetPrefix, but others are missing it, resulting in 404 errors.
Has anyone encountered this issue or found a reliable solution?
Additional information
Beta Was this translation helpful? Give feedback.
All reactions