simplify route invocations for example
This commit is contained in:
parent
ce44469e3a
commit
fa57527066
1 changed files with 9 additions and 7 deletions
16
src/index.ts
16
src/index.ts
|
|
@ -2,21 +2,23 @@ import { createUser, getUser } from "./db/util";
|
|||
Bun.serve({
|
||||
port: Number(process.env.PORT) || 3000,
|
||||
routes: {
|
||||
"/": (req) => {
|
||||
"/": () => {
|
||||
return new Response("Welcome to the landing page!", { status: 200 });
|
||||
},
|
||||
"/public/*": (req) => {
|
||||
const filePath = `./src/public${req.url.slice(7)}`;
|
||||
if (Bun.file(filePath).size) return new Response(Bun.file(filePath));
|
||||
return new Response("File not found", { status: 404 });
|
||||
if (Bun.file(filePath).size) {
|
||||
return new Response(Bun.file(filePath));
|
||||
} else {
|
||||
return new Response("File not found", { status: 404 });
|
||||
}
|
||||
},
|
||||
"/api/users/:email": async (req) => {
|
||||
const users = await getUser(req.params.email);
|
||||
return Response.json(users);
|
||||
return Response.json(await getUser(req.params.email));
|
||||
},
|
||||
"/api/create": () => {
|
||||
"/api/create": async () => {
|
||||
return Response.json(
|
||||
createUser("Badtz", 27, "me@badtz.dev").then((user) =>
|
||||
await createUser("Badtz", 27, "me@badtz.dev").then((user) =>
|
||||
JSON.stringify(user)
|
||||
)
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue