Skip to content

Commit

Permalink
Serve locally with Node, Deno, Bun
Browse files Browse the repository at this point in the history
  • Loading branch information
johnd0e committed Oct 20, 2024
1 parent 9a173d3 commit c61ff2d
Show file tree
Hide file tree
Showing 6 changed files with 537 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bun.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import worker from "./src/worker.mjs";

worker.port = +(process.env.PORT || 8080);
const environment = process.env.NODE_ENV ?? "development"
worker.development = process.env.NODE_ENV==="development"

const server = Bun.serve(worker);
console.log(`[${environment}] Listening on ${server.url.origin}`);
8 changes: 8 additions & 0 deletions deno.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//deprecated:
//import {serve} from "https://deno.land/std/http/mod.ts"

import worker from "./src/worker.mjs";

const port = +(process.env.PORT || 8080);

Deno.serve({port}, worker.fetch);
11 changes: 11 additions & 0 deletions node.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createServerAdapter } from '@whatwg-node/server'
import { createServer } from 'node:http'
import worker from "./src/worker.mjs";

const port = +(process.env.PORT || 8080);

const serverAdapter = createServerAdapter(worker.fetch)
const server = createServer(serverAdapter)
server.listen(port, () => {
console.log('Listening on:', server.address());
})
Loading

0 comments on commit c61ff2d

Please sign in to comment.