Created
September 30, 2023 06:53
-
-
Save virasak/ec2b2ac239631b2c989f53c91bc638fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
# Start an Express Server | |
- Requests to install `express` and `detect-port` | |
- Starts an express server | |
- Opens the local url once server is running | |
*/ | |
// Name: Express Server | |
// Description: Start an Express server | |
// Author: John Lindquist | |
// Twitter: @johnlindquist | |
import "@johnlindquist/kit" | |
let { default: express } = await import("express") | |
let { default: detectPort } = await import("detect-port") | |
let app = express() | |
let port = await detectPort(3000) | |
app.get("/", async (req, res) => { | |
let content = await readFile(kitPath("API.md"), "utf-8") | |
let style = `<style> | |
body { | |
font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif; | |
} | |
</style>` | |
let html = style + md(content) | |
res.send(html) | |
}) | |
let url = `http://localhost:${port}` | |
app.listen(port, async () => { | |
await div( | |
md(` | |
# Server running at [${url}](${url}) | |
## How to End Long-Running Scripts | |
Press "${cmd}+p" from the Main Menu to open the Process Manager. Select the process you want to end. | |
![http://res.cloudinary.com/johnlindquist/image/upload/v1689094925/clipboard/stzc2z4dsi15wrwdctao.png](http://res.cloudinary.com/johnlindquist/image/upload/v1689094925/clipboard/stzc2z4dsi15wrwdctao.png) | |
`) | |
) | |
// If a script is going to stay "alive", you need to manually call `hide()` to hide the prompt | |
hide() | |
}) | |
open(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment