add https support for dev server (#1548)

This commit is contained in:
Alexander Rose
2025-06-24 03:41:07 -07:00
committed by GitHub
parent 3675c0afe0
commit 2384003f5d
2 changed files with 13 additions and 2 deletions

3
.gitignore vendored
View File

@@ -13,3 +13,6 @@ tsconfig.commonjs.tsbuildinfo
.DS_Store
tmp/
dev.pem
dev-key.pem

View File

@@ -273,19 +273,27 @@ async function main() {
console.log('Initial build complete.');
const certfile = './dev.pem';
const keyfile = './dev-key.pem';
const sslEnabled = fs.existsSync(certfile) && fs.existsSync(keyfile);
const protocol = sslEnabled ? 'https' : 'http';
const ctx = await esbuild.context({});
ctx.serve({
servedir: './',
port: args.port,
host: '0.0.0.0', // Always listen on all interfaces
certfile: sslEnabled ? certfile : undefined,
keyfile: sslEnabled ? keyfile : undefined,
});
console.log('');
console.log(`Server URL: http://localhost:${args.port}`);
console.log(`Server URL: ${protocol}://localhost:${args.port}`);
if (args.host) {
console.log('Available host addresses:');
const ips = getLocalIPs();
ips.forEach(ip => console.log(` http://${ip}:${args.port}`));
ips.forEach(ip => console.log(` ${protocol}://${ip}:${args.port}`));
}
console.log('');
console.log('Watching for changes...');