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