aboutsummaryrefslogtreecommitdiff
path: root/examples/http.ts
blob: 8b17c320ccca7711316806431c86d09ff0109450 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Start a fast HTTP server from a function
Bun.serve({
  fetch(req: Request) {
    return new Response(`Echo: ${req.url}`);
  },

  // baseURI: "http://localhost:3000",

  // this is called when fetch() throws or rejects
  // error(err: Error) {
  //   return new Response("uh oh! :(\n" + err.toString(), { status: 500 });
  // },

  // this boolean enables bun's default error handler
  development: process.env.NODE_ENV !== "production",
  // note: this isn't node, but for compatibility bun supports process.env + more stuff in process

  // SSL is enabled if these two are set
  // certFile: './cert.pem',
  // keyFile: './key.pem',

  port: 3000, // number or string
});
// Start a fast HTTP server from the main file's export
// export default {
//   fetch(req) {
//     return new Response(
//       `This is another way to start a server!
//        if the main file export default's an object
//        with 'fetch'. Bun automatically calls Bun.serve`
//     );
//   },
//   // so autocomplete & type checking works
// } as Bun.Serve;
ight='13' alt='Gravatar' /> Jarred Sumner 4-1/+60 2022-04-02[bun.js] fs.readSync & fs.writeSync should return just the numberGravatar Jarred Sumner 1-24/+57 2022-04-02[bun.js] Support `mode` and `flags` as integer args in fs.openSync (instead ↵Gravatar Jarred Sumner 1-0/+6 of only object) 2022-04-02Update base.zigGravatar Jarred Sumner 1-0/+1 2022-04-02Fix GC bug when reading TypedArray from user inputGravatar Jarred Sumner 1-6/+36 2022-04-02s/Buffer/TypedArrayGravatar Jarred Sumner 1-17/+17 2022-04-02Fix mmap on macOS x64Gravatar Jarred Sumner 2-29/+27