diff --git a/docker-compose.yml b/docker-compose.yml index bc2525a..6644956 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,39 +1,43 @@ version: "3" services: - nextjs: - build: . - ports: - - "3000:3000" - networks: - - surrealdb + nextjs: + build: . + env_file: + - .env + ports: + - "3000:3000" + depends_on: + - surrealdb + networks: + - surrealdb - surrealdb: - container_name: surrealdb - image: surrealdb/surrealdb:latest - env_file: - - .env - entrypoint: - - /surreal - - start - - --user - - $DB_USER - - --pass - - $DB_PASSWORD - - file:/data/surrealdb - restart: always - deploy: - resources: - reservations: - cpus: "1" - ports: - - 8000:8000 - volumes: - - ./data:/data - networks: - - surrealdb + surrealdb: + container_name: surrealdb + image: surrealdb/surrealdb:latest-dev + env_file: + - .env + entrypoint: + - /surreal + - start + - --user + - $DB_USER + - --pass + - $DB_PASSWORD + - file:/data/surrealdb + restart: always + deploy: + resources: + reservations: + cpus: "1" + ports: + - 8000:8000 + volumes: + - ./data:/data + networks: + - surrealdb volumes: - data: + data: networks: - surrealdb: + surrealdb: diff --git a/next.config.js b/next.config.js index 767719f..7ad78ee 100644 --- a/next.config.js +++ b/next.config.js @@ -1,4 +1,6 @@ /** @type {import('next').NextConfig} */ -const nextConfig = {} +const nextConfig = { + output: "standalone", +} module.exports = nextConfig diff --git a/src/app/[slug]/db.tsx b/src/app/[slug]/db.tsx index a07fcd1..bcb4db2 100644 --- a/src/app/[slug]/db.tsx +++ b/src/app/[slug]/db.tsx @@ -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; + } } diff --git a/src/app/[slug]/page.tsx b/src/app/[slug]/page.tsx index 1790ea3..7b0f42a 100644 --- a/src/app/[slug]/page.tsx +++ b/src/app/[slug]/page.tsx @@ -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}`); } diff --git a/src/app/create/db.tsx b/src/app/create/db.tsx index 41f65fd..102e47c 100644 --- a/src/app/create/db.tsx +++ b/src/app/create/db.tsx @@ -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 }; } diff --git a/src/app/stats/page.tsx b/src/app/stats/page.tsx new file mode 100644 index 0000000..a5bf2a4 --- /dev/null +++ b/src/app/stats/page.tsx @@ -0,0 +1,8 @@ + +export default function StatsPage() { + return ( +
+

Stats

+
+ ); +} \ No newline at end of file diff --git a/src/components/db-utils.tsx b/src/components/db-utils.tsx index b7a25be..0079c17 100644 --- a/src/components/db-utils.tsx +++ b/src/components/db-utils.tsx @@ -5,14 +5,14 @@ const db = new Surreal(); export async function initConnection(): Promise { 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) {