fix(deploy): add _next static asset symlink automation to fix blank white screen and TDD test pass
This commit is contained in:
1 parent
09cc05829e
commit
d7561dc85d
4 files changed
+100
No files matched your search
@@ -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"',
|
||||
|
||||
@@ -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"'
|
||||
|
||||
@@ -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);
|
||||
Reference in new issue
Block a user