Skip to content

Commit

Permalink
API Bun.serve
Browse files Browse the repository at this point in the history
  • Loading branch information
dvque committed Feb 3, 2024
1 parent 518505c commit df3b9c8
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 16 deletions.
9 changes: 0 additions & 9 deletions src/api.ts

This file was deleted.

26 changes: 26 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { fetchUserProfile } from "../lib/fetch";

const server = Bun.serve({
port: 1234,
async fetch(request) {
const { pathname, searchParams } = new URL(request.url);

if(pathname.startsWith("/api/users/")) {
const userId = searchParams.get("userId")!;
const userName = searchParams.get("userName")!;

const data = await fetchUserProfile({ userId: userId, userName: userName })

return new Response(JSON.stringify(data), {
headers: {
"content-type": "application/json",
},
});
}

return new Response(null, { status: 404 });

},
})

console.log(`Listening on localhost:${server.port}`)
7 changes: 0 additions & 7 deletions src/index.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './fetch'

0 comments on commit df3b9c8

Please sign in to comment.