Skip to content

Commit

Permalink
Open serve url
Browse files Browse the repository at this point in the history
  • Loading branch information
platypii committed Jun 6, 2024
1 parent 0b43615 commit 9cb41cf
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Dependency-free http server for serving static files
*/

import { exec } from 'child_process'
import fs from 'fs/promises'
import http from 'http'
import path from 'path'
Expand Down Expand Up @@ -127,6 +128,7 @@ export function serve(port = 2048) {
}
}).listen(port, () => {
console.log(`hyperparam server running on http://localhost:${port}`)
openUrl(`http://localhost:${port}`)
})
}

Expand All @@ -143,3 +145,15 @@ function gzip(req, content) {
return zlib.gzipSync(content)
}
}

/**
* @param {string} url
*/
function openUrl(url) {
switch (process.platform) {
case 'darwin': return exec(`open ${url}`)
case 'win32': return exec(`start ${url}`)
case 'linux': return exec(`xdg-open ${url}`)
default: throw new Error(`unsupported platform ${process.platform}`)
}
}

0 comments on commit 9cb41cf

Please sign in to comment.