diff options
author | 2022-04-06 01:52:15 -0700 | |
---|---|---|
committer | 2022-04-06 01:53:05 -0700 | |
commit | 81eb47de0eb08081ed0677b71aa47e9a2b473cab (patch) | |
tree | 051df34c66832ab2f0986370d5c8fbb3e12058fc /examples/openInEditor.js | |
parent | 57cf035a73187439fbcd8703d7f4358463ee8314 (diff) | |
download | bun-81eb47de0eb08081ed0677b71aa47e9a2b473cab.tar.gz bun-81eb47de0eb08081ed0677b71aa47e9a2b473cab.tar.zst bun-81eb47de0eb08081ed0677b71aa47e9a2b473cab.zip |
[bun.js] Add stdout, stderr, stdin to Bun and support sendfile() + splice()
Diffstat (limited to 'examples/openInEditor.js')
-rw-r--r-- | examples/openInEditor.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/examples/openInEditor.js b/examples/openInEditor.js new file mode 100644 index 000000000..59282c098 --- /dev/null +++ b/examples/openInEditor.js @@ -0,0 +1,23 @@ +import { resolve } from "path"; +import { parse } from "querystring"; + +export default { + fetch(req) { + if (req.url === "/favicon.ico") + return new Response("nooo dont open favicon in editor", { status: 404 }); + + var pathname = req.url.substring(1); + const q = pathname.indexOf("?"); + var { editor } = parse(pathname.substring(q + 1)) || {}; + + if (q > 0) { + pathname = pathname.substring(0, q); + } + + Bun.openInEditor(resolve(pathname), { + editor, + }); + + return new Response(`Opened ${req.url}`); + }, +}; |