1- import { spawn , type ChildProcess } from "child_process"
1+ import { spawn , spawnSync , type ChildProcess } from "child_process"
22import { writeFileSync } from "fs"
33import { readFileSync } from "fs"
44import { networkInterfaces } from "os"
@@ -124,9 +124,28 @@ ${networkIP} {
124124 const startCaddyIfReady = ( projectName : string ) => {
125125 if ( autoStart && vitePort && ! caddyStarted ) {
126126 caddyStarted = true
127+
128+ // Check if `caddy` binary is available before starting (sync)
129+ try {
130+ const check = spawnSync ( `caddy` , [ `--version` ] , { stdio : `ignore` } )
131+ if ( check . error || check . status !== 0 ) {
132+ throw new Error (
133+ `\`caddy\` binary not found or is not working. Please ensure Caddy is installed and available in your PATH.`
134+ )
135+ }
136+ } catch ( _err ) {
137+ console . error (
138+ `\`caddy\` binary not found or is not working. Please ensure Caddy is installed and available in your PATH.` ,
139+ `\nCaddy is required to be able to serve local development with HTTP2 support.` ,
140+ `\n - Install Caddy: https://caddyserver.com/docs/install` ,
141+ `\n - If you have \`asdf\`, run \`asdf install\``
142+ )
143+ process . exit ( 1 )
144+ }
127145 // Generate Caddyfile
128146 const caddyConfig = generateCaddyfile ( projectName , vitePort )
129147 writeFileSync ( configPath , caddyConfig )
148+
130149 // Start Caddy
131150 startCaddy ( configPath )
132151 }
@@ -172,8 +191,10 @@ ${networkIP} {
172191 console . log ( )
173192 console . log ( ` ➜ Local: https://${ projectName } .localhost/` )
174193 console . log ( ` ➜ Network: https://${ networkIP } /` )
175- console . log ( ` ➜ press h + enter to show help` )
176194 console . log ( )
195+ console . log (
196+ ` Note: running through Caddy. You might be prompted for password to install HTTPS certificates for local development.`
197+ )
177198 }
178199
179200 server . middlewares . use ( ( _req , _res , next ) => {
@@ -185,12 +206,12 @@ ${networkIP} {
185206 } )
186207
187208 const originalListen = server . listen
188- server . listen = function ( port ?: number , ... args : unknown [ ] ) {
209+ server . listen = function ( port ?: number , isRestart ?: boolean ) {
189210 if ( port ) {
190211 vitePort = port
191212 }
192213
193- const result = originalListen . call ( this , port , ... args )
214+ const result = originalListen . call ( this , port , isRestart )
194215
195216 // Try to start Caddy after server is listening
196217 if ( result && typeof result . then === `function` ) {
0 commit comments