fix redirect
This commit is contained in:
parent
dbf0b5d670
commit
ff6ed19606
7 changed files with 76 additions and 45 deletions
|
@ -2,14 +2,18 @@ version: "3"
|
||||||
services:
|
services:
|
||||||
nextjs:
|
nextjs:
|
||||||
build: .
|
build: .
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "3000:3000"
|
||||||
|
depends_on:
|
||||||
|
- surrealdb
|
||||||
networks:
|
networks:
|
||||||
- surrealdb
|
- surrealdb
|
||||||
|
|
||||||
surrealdb:
|
surrealdb:
|
||||||
container_name: surrealdb
|
container_name: surrealdb
|
||||||
image: surrealdb/surrealdb:latest
|
image: surrealdb/surrealdb:latest-dev
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
entrypoint:
|
entrypoint:
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {}
|
const nextConfig = {
|
||||||
|
output: "standalone",
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = nextConfig
|
module.exports = nextConfig
|
||||||
|
|
|
@ -2,11 +2,17 @@
|
||||||
import { initConnection } from "@/components/db-utils";
|
import { initConnection } from "@/components/db-utils";
|
||||||
|
|
||||||
export async function querydb(slug: string) {
|
export async function querydb(slug: string) {
|
||||||
|
try {
|
||||||
let db = await initConnection();
|
let db = await initConnection();
|
||||||
let long_url = await db.query(`
|
let long_url = await db.query(`
|
||||||
|
update url:[$id] set clicks = clicks + 1 ;
|
||||||
select * from url:[$id];
|
select * from url:[$id];
|
||||||
`, { id: slug });
|
`, { id: slug });
|
||||||
|
|
||||||
console.log(long_url, slug)
|
// @ts-ignore
|
||||||
|
long_url = long_url[0][0].long_url;
|
||||||
return 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";
|
import { querydb } from "./db";
|
||||||
|
|
||||||
// export default function Page({ params }: { params: { slug: string } }) {
|
// export default function Page({ params }: { params: { slug: string } }) {
|
||||||
// redirect(`https://${params.slug}`)
|
// redirect(`https://${params.slug}`)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
export default function Page({ params }: { params: { slug: string } }) {
|
export default async function Page({ params }: { params: { slug: string } }) {
|
||||||
redirect(`https://${querydb(params.slug)}`)
|
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];
|
} return id[0];
|
||||||
`, { long_url: long_url });
|
`, { long_url: long_url });
|
||||||
|
|
||||||
console.log(long_url, url)
|
// @ts-ignore
|
||||||
|
url = url[0][0].id;
|
||||||
|
|
||||||
return { url: url };
|
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> {
|
export async function initConnection(): Promise<Surreal> {
|
||||||
try {
|
try {
|
||||||
db.connect(process.env.DB_PORT + '/rpc', {
|
db.connect("http://" + process.env.DB_PORT + "/rpc", {
|
||||||
namespace: 'url',
|
namespace: 'url',
|
||||||
database: 'url',
|
database: 'url',
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
auth: {
|
auth: {
|
||||||
username: process.env.DB_USER,
|
username: process.env.DB_USER,
|
||||||
password: process.env.DB_PASSWORD,
|
password: process.env.DB_PASSWORD,
|
||||||
scope: '',
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue