From 7adca9695a11d16734521698777cd038a96b1c58 Mon Sep 17 00:00:00 2001 From: Boyu Guo Date: Sat, 8 Mar 2025 10:41:12 +0800 Subject: [PATCH 1/2] fix "TypeError: process.stdin.setRawMode is not a function" when TTY is not available --- src/studio.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/studio.ts b/src/studio.ts index 826a6fb..eff1e1a 100644 --- a/src/studio.ts +++ b/src/studio.ts @@ -157,20 +157,22 @@ export function serve( const server = app.listen(port); printServingMessage(port); - console.log("Press q | shutdown the server"); + if (process.stdin.isTTY) { + console.log("Press q | shutdown the server"); - process.stdin.setRawMode(true); - process.stdin.resume(); + process.stdin.setRawMode(true); + process.stdin.resume(); - process.stdin.on("data", (buffer) => { - const c = new TextDecoder().decode(buffer); + process.stdin.on("data", (buffer) => { + const c = new TextDecoder().decode(buffer); - if (c.toUpperCase() === "Q" || buffer[0] === 3) { - console.log("Shutting down the server"); - server.closeAllConnections(); - process.exit(); - } - }); + if (c.toUpperCase() === "Q" || buffer[0] === 3) { + console.log("Shutting down the server"); + server.closeAllConnections(); + process.exit(); + } + }); + } process.on("SIGINT", function () { console.log("Caught interrupt signal"); From df7df8dcfeb201df596721341082834a10838bfa Mon Sep 17 00:00:00 2001 From: Boyu Guo Date: Sat, 8 Mar 2025 10:46:31 +0800 Subject: [PATCH 2/2] add --base-path option for reverse proxy support --- src/index.ts | 3 +++ src/studio.ts | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index 8b2d974..d9a454c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,6 +15,7 @@ program .name("@outerbase/studio") .version("0.1.0") .option("--port ", "Set port to serve", "4000") + .option("--base-path ", "Set the base path for the web application", "/") .option("--user ", "Set basic authentication username") .option("--pass ", "Set basic authentication password") .option("--config ", "Launch studio using configuration file") @@ -27,6 +28,7 @@ program pass?: string; user?: string; port?: number; + basePath?: string; config?: string; log?: boolean; } @@ -34,6 +36,7 @@ program let options: ServeOptions = { driver: null, port: flags?.port ?? 4000, + basePath: flags?.basePath ?? "/", studio: STUDIO_PATH, username: flags?.user, password: flags?.pass, diff --git a/src/studio.ts b/src/studio.ts index eff1e1a..7f2d579 100644 --- a/src/studio.ts +++ b/src/studio.ts @@ -28,7 +28,7 @@ const htmlCode = `