Skip to content

Commit 260a942

Browse files
committed
imporove debug logging in studio-mode webserver
1 parent 856d5a2 commit 260a942

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

.github/workflows/ci-pkg-cli.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,13 @@ jobs:
9393
- name: Start studio mode for custom questions workflow
9494
working-directory: packages/cli/testproject-empty
9595
run: |
96-
npx skuilder studio --no-browser &
96+
npx skuilder studio --no-browser > ../../studio.log 2>&1 &
97+
STUDIO_PID=$!
98+
echo "Studio process started with PID: $STUDIO_PID"
99+
sleep 5
100+
echo "Checking if studio process is still running..."
101+
ps -p $STUDIO_PID || echo "WARNING: Studio process already exited"
102+
echo "Waiting for studio server to be ready..."
97103
npx wait-on http://localhost:7174 --timeout 120000
98104
99105
- name: Run custom questions studio mode tests
@@ -112,6 +118,15 @@ jobs:
112118
run: |
113119
npm run dev &
114120
npx wait-on http://localhost:6173 --timeout 60000
121+
122+
- name: Upload studio log on failure
123+
uses: actions/upload-artifact@v4
124+
if: failure()
125+
with:
126+
name: studio-log
127+
path: packages/cli/studio.log
128+
retention-days: 7
129+
115130
- name: Upload screenshots on failure
116131
uses: actions/upload-artifact@v4
117132
if: failure()

packages/cli/src/commands/studio.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,13 @@ async function startStudioUIServer(
432432

433433
console.log(chalk.gray(` Serving studio-ui from: ${studioSourcePath}`));
434434

435+
const indexHtmlPath = path.join(studioSourcePath, 'index.html');
436+
if (!fs.existsSync(indexHtmlPath)) {
437+
console.error(chalk.red(` ERROR: index.html not found at ${indexHtmlPath}`));
438+
throw new Error(`Studio-UI index.html missing at ${indexHtmlPath}`);
439+
}
440+
console.log(chalk.gray(` Verified index.html exists at: ${indexHtmlPath}`));
441+
435442
const serve = serveStatic(studioSourcePath, {
436443
index: ['index.html'],
437444
setHeaders: (res, path) => {
@@ -457,10 +464,12 @@ async function startStudioUIServer(
457464
try {
458465
await new Promise<void>((resolve, reject) => {
459466
const server = http.createServer((req, res) => {
460-
const url = new URL(req.url || '/', `http://${req.headers.host}`);
467+
try {
468+
console.log(chalk.gray(` [Studio HTTP] ${req.method} ${req.url} from ${req.socket.remoteAddress}`));
469+
const url = new URL(req.url || '/', `http://${req.headers.host || 'localhost:7174'}`);
461470

462-
// Inject config for index.html
463-
if (url.pathname === '/' || url.pathname === '/index.html') {
471+
// Inject config for index.html
472+
if (url.pathname === '/' || url.pathname === '/index.html') {
464473
const indexPath = path.join(studioSourcePath, 'index.html');
465474
let html = fs.readFileSync(indexPath, 'utf8');
466475
const connectionScript = `
@@ -517,14 +526,31 @@ async function startStudioUIServer(
517526
res.setHeader('Content-Type', 'text/html');
518527
res.end(html);
519528
});
529+
} catch (error) {
530+
console.error(chalk.red(` [Studio HTTP] Error handling request: ${error}`));
531+
res.statusCode = 500;
532+
res.end('Internal Server Error');
533+
}
534+
});
535+
536+
server.on('listening', () => {
537+
const addr = server.address();
538+
console.log(chalk.gray(` [Studio HTTP] Server listening event fired, address: ${JSON.stringify(addr)}`));
539+
});
540+
541+
server.on('connection', (socket) => {
542+
console.log(chalk.gray(` [Studio HTTP] New connection from ${socket.remoteAddress}:${socket.remotePort}`));
520543
});
521544

522545
server.listen(port, '0.0.0.0', () => {
523546
studioUIServer = server;
547+
const addr = server.address();
548+
console.log(chalk.gray(` [Studio HTTP] Listen callback fired, address: ${JSON.stringify(addr)}`));
524549
resolve();
525550
});
526551

527552
server.on('error', (err: NodeJS.ErrnoException) => {
553+
console.error(chalk.red(` [Studio HTTP] Server error: ${err.code} - ${err.message}`));
528554
if (err.code === 'EADDRINUSE') {
529555
reject(err);
530556
} else {

0 commit comments

Comments
 (0)