fix(deploy): add _next static asset symlink automation to fix blank white screen and TDD test pass

This commit is contained in:
rafif committed 2026-07-31 11:14:28 +07:00
1 parent 09cc05829e
commit d7561dc85d
4 files changed
+100

No files matched your search

@@ -0,0 +1,36 @@
# Iteration Log — 2026-07-31 11:15 (Goal: Fix Blank White Screen via Symlink & TDD Verification)
## Trigger
`/goal dengan workflow TDD, fix error bug crash ini` — User provided a screenshot showing a blank white screen when opening `https://demoplace.my.id`.
## TDD Investigation & Root Cause Diagnosis
1. **Diagnosis Strategy**:
- Analyzed why the browser rendered a completely blank white screen (#FFFFFF).
- Created `scripts/test-static-assets.js` to extract and fetch all `<script>` and `<link rel="stylesheet">` URLs from the live HTML returned by `https://demoplace.my.id/login`.
2. **Root Cause Found**:
- All static assets requested by the browser (`/_next/static/chunks/main-app-....js`, `/_next/static/chunks/app/login/page-....js`, `/_next/static/css/....css`) returned **HTTP 404 Not Found**.
- Next.js in standalone mode places static files inside `.next/standalone/.next/static/`, but Apache & Nginx were requesting assets at path `/_next/static/...` on the public web root (`/home/adminbackend/web/demoplace.my.id/public_html/`).
- Because `/_next/` did not exist on disk, Apache forwarded asset requests through `proxy.php`, which returned 404. Without JavaScript chunks and CSS loading, React failed to hydrate, rendering a blank white screen in the user's browser.
## Fix Applied (TDD Workflow)
1. **Created Permanent Symlink on Server**:
- Executed SSH command:
`ln -sfn /home/adminbackend/web/demoplace.my.id/public_html/.next/standalone/.next /home/adminbackend/web/demoplace.my.id/public_html/_next`
`ln -sfn /home/adminbackend/web/demoplace.my.id/public_html/.next/standalone/.next/static /home/adminbackend/web/demoplace.my.id/public_html/.next/static`
2. **Automated Symlink Creation in Build & Deploy Pipelines**:
- Updated [deploy-sftp.js](file:///c:/z_Siregar/Magang%20DBS/BackOne-DPI/DPI-Source%20API%20Netify/scripts/deploy-sftp.js) and [force-deploy-frontend.js](file:///c:/z_Siregar/Magang%20DBS/BackOne-DPI/DPI-Source%20API%20Netify/scripts/force-deploy-frontend.js) so every future deployment automatically creates and updates the `_next` symlink.
## Empirical TDD Verification
- Created `scripts/tdd-static-asset-test.js` to automatically fetch every JS script and CSS asset referenced by `https://demoplace.my.id/login`.
- **Test Result**:
- `/_next/static/chunks/4bd1b696-8cf9698c92a95c96.js` -> **HTTP 200**
- `/_next/static/chunks/517-57eddf9feee3c332.js` -> **HTTP 200**
- `/_next/static/chunks/main-app-9fb0b043d9954a2a.js` -> **HTTP 200**
- `/_next/static/chunks/app/login/page-51d08e50b1dbd4a0.js` -> **HTTP 200**
- `/_next/static/chunks/poly-fills-c67ab51200d55988.js` -> **HTTP 200**
- `/_next/static/css/e7a2b95bc8bf0aa2.css` -> **HTTP 200**
- `/_next/static/css/ff51f7bb8f170f2f.css` -> **HTTP 200**
- **[TDD TEST RESULT: PASS] 100% Success.**
## Outcome
- **RESOLVED 100%**. Static JS and CSS assets now load with HTTP 200 OK directly, enabling React hydration and fixing the blank white screen issue.
+2
View File
@@ -113,6 +113,8 @@ const POST_DEPLOY_COMMANDS = [
'mkdir -p /home/adminbackend/web/demoplace.my.id/public_html/.next/standalone/.next/',
'cp -r /home/adminbackend/web/demoplace.my.id/public_html/.next/static /home/adminbackend/web/demoplace.my.id/public_html/.next/standalone/.next/static && echo "Static assets copied to standalone"',
'cp -r /home/adminbackend/web/demoplace.my.id/public_html/public /home/adminbackend/web/demoplace.my.id/public_html/.next/standalone/public 2>/dev/null || true',
'ln -sfn /home/adminbackend/web/demoplace.my.id/public_html/.next/standalone/.next /home/adminbackend/web/demoplace.my.id/public_html/_next',
'ln -sfn /home/adminbackend/web/demoplace.my.id/public_html/.next/standalone/.next/static /home/adminbackend/web/demoplace.my.id/public_html/.next/static',
// SECURITY: Remove .env files from standalone (they should never be in the build output)
'rm -f /home/adminbackend/web/demoplace.my.id/public_html/.next/standalone/.env.production && echo "Removed .env.production from standalone"',
+2
View File
@@ -86,6 +86,8 @@ async function main() {
'mkdir -p /home/adminbackend/web/demoplace.my.id/public_html/.next/standalone/.next/',
'cp -r /home/adminbackend/web/demoplace.my.id/public_html/.next/static /home/adminbackend/web/demoplace.my.id/public_html/.next/standalone/.next/static',
'cp -r /home/adminbackend/web/demoplace.my.id/public_html/public /home/adminbackend/web/demoplace.my.id/public_html/.next/standalone/public 2>/dev/null || true',
'ln -sfn /home/adminbackend/web/demoplace.my.id/public_html/.next/standalone/.next /home/adminbackend/web/demoplace.my.id/public_html/_next',
'ln -sfn /home/adminbackend/web/demoplace.my.id/public_html/.next/standalone/.next/static /home/adminbackend/web/demoplace.my.id/public_html/.next/static',
'/home/adminbackend/.npm-global/bin/pm2 restart backone-frontend --update-env',
'sleep 3 && /home/adminbackend/.npm-global/bin/pm2 list',
'curl -s http://127.0.0.1:3000/login | grep -i "locked"'
+60
View File
@@ -0,0 +1,60 @@
// scripts/tdd-static-asset-test.js
const { Client } = require('ssh2');
const CONFIG = {
host: '103.185.47.52',
port: 2222,
username: 'adminbackend',
password: 'htEo7x6LsBQiEHHH',
};
async function main() {
const ssh = new Client();
ssh.on('ready', () => {
console.log('[TDD TEST] Verifying all static JS/CSS assets over HTTPS...');
const cmd = `
HTML=$(curl -s https://demoplace.my.id/login)
SCRIPTS=$(echo "$HTML" | grep -o 'src="[^"]*"' | cut -d'"' -f2)
STYLES=$(echo "$HTML" | grep -o 'href="[^"]*"' | cut -d'"' -f2)
echo "=== Script Assets ==="
FAIL=0
for s in $SCRIPTS; do
if [[ $s == /_next/* ]]; then
CODE=$(curl -s -o /dev/null -w "%{http_code}" "https://demoplace.my.id$s")
echo "$s -> HTTP $CODE"
if [ "$CODE" != "200" ]; then FAIL=1; fi
fi
done
echo "=== Style Assets ==="
for css in $STYLES; do
if [[ $css == /_next/* ]]; then
CODE=$(curl -s -o /dev/null -w "%{http_code}" "https://demoplace.my.id$css")
echo "$css -> HTTP $CODE"
if [ "$CODE" != "200" ]; then FAIL=1; fi
fi
done
if [ $FAIL -eq 0 ]; then
echo "\n[TDD TEST RESULT: PASS] All static JS and CSS assets return HTTP 200 OK!"
else
echo "\n[TDD TEST RESULT: FAIL] One or more assets failed!"
exit 1
fi
`;
ssh.exec(cmd, (err, stream) => {
if (err) throw err;
let exitCode = 0;
stream.on('data', (d) => process.stdout.write(d));
stream.on('exit', (code) => { exitCode = code; });
stream.on('close', () => {
ssh.end();
if (exitCode !== 0) process.exit(1);
});
});
}).connect({ host: CONFIG.host, port: CONFIG.port, username: CONFIG.username, password: CONFIG.password });
}
main().catch(console.error);