diff --git a/index.ts b/index.ts index 3c2629a..127f40a 100644 --- a/index.ts +++ b/index.ts @@ -5,10 +5,10 @@ Bun.serve({ port: Bun.env.PORT || 8080, async fetch(req) { const url = new URL(req.url); - if (req.method == "POST" && url.pathname == "/admin") { + if (req.method === "POST" && url.pathname === "/admin") { if (req.body) { const { urlData, password } = await req.json() as { urlData: string, password: string }; - if (urlData && password == Bun.env.ADMIN_PASSWORD) { + if (urlData && password === Bun.env.ADMIN_PASSWORD) { const u = await prisma.url.create({ data: { url: urlData @@ -21,7 +21,7 @@ Bun.serve({ } } } - else if (req.method == "GET") { + else if (req.method === "GET") { const urlRes = await prisma.url.findFirst({ orderBy: { updatedAt: "desc" diff --git a/noDb.ts b/noDb.ts new file mode 100644 index 0000000..9cb7ba4 --- /dev/null +++ b/noDb.ts @@ -0,0 +1,31 @@ +let urlToRedirect = Bun.env.URL_TO_REDIRECT || "https://instagram.com/modelec_isen"; + +Bun.serve({ + port: Bun.env.PORT || 8080, + async fetch(req) { + const url = new URL(req.url); + if (req.method === "POST" && url.pathname === "/admin") { + if (req.body) { + const { u, password } = await req.json() as { u: string, password: string }; + if (u && password === Bun.env.ADMIN_PASSWORD) { + urlToRedirect = u; + + return new Response(JSON.stringify({body: u}), { + status: 200 + }) + } + } + } + else if (req.method === "GET") { + return new Response(null, { + status: 302, + headers: { + Location: urlToRedirect + } + }) + } + return new Response("err", { + status: 400 + }) + } +}) \ No newline at end of file diff --git a/package.json b/package.json index 9a36801..d61c019 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ "@prisma/client": "5.8.1" }, "scripts": { - "dev": "bun run index.ts", - "build": "bun build", + "dev": "bun run noDb.ts", + "dev:db": "bun run index.ts", "prisma:migrate:dev": "bunx prisma migrate dev", "prisma:migrate:generate": "bunx prisma generate", "prisma:studio": "bunx prisma studio"