-
+
diff --git a/app/api/s/route.ts b/app/api/s/route.ts
index d6fb918..4314292 100644
--- a/app/api/s/route.ts
+++ b/app/api/s/route.ts
@@ -7,21 +7,25 @@ export async function GET(req: NextRequest) {
const url = new URL(req.url);
const slug = url.searchParams.get("slug");
const ip = url.searchParams.get("ip");
+ const city = url.searchParams.get("city");
+ const region = url.searchParams.get("region");
+ const country = url.searchParams.get("country");
+ const latitude = url.searchParams.get("latitude");
+ const longitude = url.searchParams.get("longitude");
if (!slug || !ip) return Response.json(null);
const res = await getUrlBySuffix(slug);
if (res?.target && res?.active === 1) {
- console.log("[api/s]", ip, res.id);
- // TODO
+ // console.log("[api/s]", ip, res.id);
await createUserShortUrlMeta({
urlId: res.id,
click: 1,
ip: ip ? ip.split(",")[0] : "127.0.0.1",
- city: "",
- region: "",
- country: "",
- latitude: "",
- longitude: "",
+ city,
+ region,
+ country,
+ latitude,
+ longitude,
});
return Response.json(res.target);
}
diff --git a/config/docs.ts b/config/docs.ts
index a4f16ec..3f21d74 100644
--- a/config/docs.ts
+++ b/config/docs.ts
@@ -43,6 +43,26 @@ export const docsConfig: DocsConfig = {
// },
],
},
+ {
+ title: "Examples",
+ items: [
+ {
+ title: "Vercel Custom Domain",
+ href: "/docs/examples/vercel",
+ icon: "page",
+ },
+ {
+ title: "Zeabur Custom Domain",
+ href: "/docs/examples/zeabur",
+ icon: "page",
+ },
+ {
+ title: "Other",
+ href: "/docs/examples/other",
+ icon: "page",
+ },
+ ],
+ },
{
title: "Developer",
items: [
diff --git a/content/docs/exanples/other.mdx b/content/docs/exanples/other.mdx
new file mode 100644
index 0000000..bcc0082
--- /dev/null
+++ b/content/docs/exanples/other.mdx
@@ -0,0 +1,5 @@
+---
+title: Other
+description: Free parsing custom domain names.
+---
+
diff --git a/content/docs/exanples/vercel.mdx b/content/docs/exanples/vercel.mdx
new file mode 100644
index 0000000..e098da7
--- /dev/null
+++ b/content/docs/exanples/vercel.mdx
@@ -0,0 +1,5 @@
+---
+title: Vercel Custom Domain
+description: Free parsing of Vercel custom domain names.
+---
+
diff --git a/content/docs/exanples/zeabur.mdx b/content/docs/exanples/zeabur.mdx
new file mode 100644
index 0000000..55ae9d8
--- /dev/null
+++ b/content/docs/exanples/zeabur.mdx
@@ -0,0 +1,4 @@
+---
+title: Zeabur Custom Domain
+description: Free parsing of Zeabur custom domain names.
+---
\ No newline at end of file
diff --git a/middleware.ts b/middleware.ts
index fa49f81..ac04b5c 100644
--- a/middleware.ts
+++ b/middleware.ts
@@ -2,22 +2,37 @@ import { NextResponse } from "next/server";
import { auth } from "auth";
import { siteConfig } from "./config/site";
-import { createUserShortUrlMeta, getUrlBySuffix } from "./lib/dto/short-urls";
// export { auth as middleware } from "auth";
-// Or like this if you need to do something here.
export default auth(async (req) => {
- // console.log(req.auth); // { session: { user: { ... } } }
+ // console.log(req.auth);
const ip = req.headers.get("X-Forwarded-For");
- // console.log("[middle/s]", ip);
if (req.url.includes("/s/")) {
- const slugRegex = /[^/]+$/;
- const match = req.url.match(slugRegex);
+ const match = req.url.match(/[^/]+$/);
+ let geo = {
+ city: "",
+ region: "",
+ country: "",
+ latitude: "",
+ longitude: "",
+ };
+ const data = await fetch(`https://ip.wr.do/api?ip=${ip}`); // http://ip-api.com/json/42.48.83.141
+ if (data.ok) {
+ const geoData = await data.json();
+ geo = {
+ city: geoData.city,
+ region: geoData.region,
+ country: geoData.country,
+ latitude: geoData.latitude,
+ longitude: geoData.longitude,
+ };
+ }
+
if (match) {
const res = await fetch(
- `${siteConfig.url}/api/s?slug=${match[0]}&ip=${ip}`,
+ `${siteConfig.url}/api/s?slug=${match[0]}&ip=${ip}&city=${geo.city}®ion=${geo.region}&country=${geo.country}&latitude=${geo.latitude}&longitude=${geo.longitude}`,
{
method: "GET",
},