mirror of
https://github.com/modelec/urlsh-qrcode.git
synced 2026-03-18 21:50:29 +01:00
add noDb version
This commit is contained in:
6
index.ts
6
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"
|
||||
|
||||
31
noDb.ts
Normal file
31
noDb.ts
Normal file
@@ -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
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user