Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions backend/server/scripts/process-public-next-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ then
if [ "$NODE_ENV" = "production" ]
then
echo "Preprocessing environment variables"
echo "This should only run on our docker build"

# Determine the project root directory
# If running in Docker, use /app, otherwise use relative path from backend/server
if [ -d "/app" ]; then
PROJECT_ROOT="/app"
else
PROJECT_ROOT="$(cd "$(dirname "$0")/../../.." && pwd)"
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 For better robustness, consider using a more reliable method to determine the project root, such as searching upwards for a marker file like package.json or .git. Relying on the script's relative path can be fragile if the script is ever moved.


echo "Using project root: $PROJECT_ROOT"

# For each of the var in .env.production, replace with proper process env
while read line; do
Expand All @@ -14,25 +23,25 @@ then

eval "ACTUAL_ENV=\$$ENV_NAME"

find /app/apps/homepage/.next -type f -name "*.js" -print0 | xargs -0 -P $(nproc) sed -i "s|$STRING_TO_REPLACE|$ACTUAL_ENV|g";
done < /app/backend/server/.env.production
find "$PROJECT_ROOT/apps/homepage/.next" -type f -name "*.js" -print0 | xargs -0 -P $(nproc) sed -i "s|$STRING_TO_REPLACE|$ACTUAL_ENV|g";
done < "$PROJECT_ROOT/backend/server/.env.production"

while read line; do
ENV_NAME=$(echo "$line" | cut -d "=" -f 1)
STRING_TO_REPLACE=$(echo "$line" | cut -d "=" -f 2)

eval "ACTUAL_ENV=\$$ENV_NAME"

find /app/apps/remote/dist -type f -name "*.js" -print0 | xargs -0 -P $(nproc) sed -i "s|$STRING_TO_REPLACE|$ACTUAL_ENV|g";
done < /app/apps/remote/.env.production
find "$PROJECT_ROOT/apps/remote/dist" -type f -name "*.js" -print0 | xargs -0 -P $(nproc) sed -i "s|$STRING_TO_REPLACE|$ACTUAL_ENV|g";
done < "$PROJECT_ROOT/apps/remote/.env.production"

while read line; do
ENV_NAME=$(echo "$line" | cut -d "=" -f 1)
STRING_TO_REPLACE=$(echo "$line" | cut -d "=" -f 2)

eval "ACTUAL_ENV=\$$ENV_NAME"

find /app/apps/renderer/dist -type f -name "*.js" -print0 | xargs -0 -P $(nproc) sed -i "s|$STRING_TO_REPLACE|$ACTUAL_ENV|g";
done < /app/apps/renderer/.env.production
find "$PROJECT_ROOT/apps/renderer/dist" -type f -name "*.js" -print0 | xargs -0 -P $(nproc) sed -i "s|$STRING_TO_REPLACE|$ACTUAL_ENV|g";
done < "$PROJECT_ROOT/apps/renderer/.env.production"
fi
fi
3 changes: 3 additions & 0 deletions e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,8 @@ export default defineConfig({
command: "yarn server start",
url: "http://localhost:5678",
reuseExistingServer: !process.env.CI,
env: {
NODE_ENV: "production",
},
},
});
Loading