fix redirect
This commit is contained in:
parent
dbf0b5d670
commit
ff6ed19606
7 changed files with 76 additions and 45 deletions
|
@ -2,11 +2,17 @@
|
|||
import { initConnection } from "@/components/db-utils";
|
||||
|
||||
export async function querydb(slug: string) {
|
||||
let db = await initConnection();
|
||||
let long_url = await db.query(`
|
||||
select * from url:[$id];
|
||||
`, { id: slug });
|
||||
try {
|
||||
let db = await initConnection();
|
||||
let long_url = await db.query(`
|
||||
update url:[$id] set clicks = clicks + 1 ;
|
||||
select * from url:[$id];
|
||||
`, { id: slug });
|
||||
|
||||
console.log(long_url, slug)
|
||||
return long_url;
|
||||
// @ts-ignore
|
||||
long_url = long_url[0][0].long_url;
|
||||
return long_url;
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,19 @@
|
|||
import { redirect } from "next/navigation";
|
||||
"use server";
|
||||
import { notFound, redirect } from "next/navigation";
|
||||
import { querydb } from "./db";
|
||||
|
||||
// export default function Page({ params }: { params: { slug: string } }) {
|
||||
// redirect(`https://${params.slug}`)
|
||||
// }
|
||||
|
||||
export default function Page({ params }: { params: { slug: string } }) {
|
||||
redirect(`https://${querydb(params.slug)}`)
|
||||
export default async function Page({ params }: { params: { slug: string } }) {
|
||||
if (params.slug == "favicon.ico") {
|
||||
return;
|
||||
}
|
||||
|
||||
let long_url = await querydb(params.slug);
|
||||
if (long_url == undefined) {
|
||||
return notFound();
|
||||
}
|
||||
redirect(`https://${long_url}`);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ export async function querydb(prevState: any, formData: FormData) {
|
|||
} return id[0];
|
||||
`, { long_url: long_url });
|
||||
|
||||
console.log(long_url, url)
|
||||
// @ts-ignore
|
||||
url = url[0][0].id;
|
||||
|
||||
return { url: url };
|
||||
}
|
||||
|
|
8
src/app/stats/page.tsx
Normal file
8
src/app/stats/page.tsx
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
export default function StatsPage() {
|
||||
return (
|
||||
<div>
|
||||
<h1>Stats</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
|
@ -5,14 +5,14 @@ const db = new Surreal();
|
|||
|
||||
export async function initConnection(): Promise<Surreal> {
|
||||
try {
|
||||
db.connect(process.env.DB_PORT + '/rpc', {
|
||||
db.connect("http://" + process.env.DB_PORT + "/rpc", {
|
||||
namespace: 'url',
|
||||
database: 'url',
|
||||
|
||||
// @ts-ignore
|
||||
auth: {
|
||||
username: process.env.DB_USER,
|
||||
password: process.env.DB_PASSWORD,
|
||||
scope: '',
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue