-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
48 lines (40 loc) · 1.15 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { Hono } from "https://deno.land/x/[email protected]/mod.ts";
import { logger } from "https://deno.land/x/[email protected]/middleware.ts";
import { kvData } from "./data.ts";
const app = new Hono();
app.use("*", logger());
app.get("/", () => new Response("", {
status: 301,
headers: {
location: "https://austinpoor.com/",
},
}));
app.get("/admin/*", (c) => c.notFound());
app.get("/_ping", (c) => c.json({ success: true }));
app.get("/_all", (c) => c.json(Object.values(kvData).map(d => ({key: d.key, link: d.link}))));
app.get("/:key", (c) => {
// Get the key param...
const key = c.req.param("key").toLowerCase();
// Is key in kvData?
if (!(key in kvData)) {
return c.notFound();
}
// Get the data for the key...
const data = kvData[key];
// Get the URL...
const url = new URL(data.link);
// If the link is internal, add the UTM source...
if (data.inner) {
url.searchParams.set("utm_source", "austinpoor.com");
}
return new Response("", {
status: 301,
headers: {
location: url.toString(),
},
});
});
// Run the server if this file is run as a script...
if (import.meta.main) {
Deno.serve(app.fetch);
}