Skip to content

Commit a6df26c

Browse files
feat: env for shortener domain
1 parent 6c4ddbd commit a6df26c

File tree

8 files changed

+32
-14
lines changed

8 files changed

+32
-14
lines changed

src/app/openapi.json/route.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { generateOpenApi } from "@ts-rest/open-api"
33
// import z from "zod"
44
import { contract } from "@/lib/contract"
5+
import { env } from "@/env";
56

67
// const ZOD_4_ASYNC: SchemaTransformerAsync = async ({ schema }) => {
78
// console.log("Converting schema:", schema)
@@ -16,11 +17,11 @@ import { contract } from "@/lib/contract"
1617

1718
const openapiDocument = generateOpenApi(contract, {
1819
info: {
19-
title: "polinet.cc API",
20+
title: `${env.DOMAIN} API`,
2021
version: "1.0.0",
2122
description: "PoliNetwork's Short URLs - Service API",
2223
},
23-
servers: [{ url: "https://polinet.cc/api" }],
24+
servers: [{ url: `https://${env.DOMAIN}/api` }],
2425
components: {
2526
securitySchemes: {
2627
CloudflareID: {

src/components/create-url-dialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { Label } from "@/components/ui/label"
1919
import { createUrl } from "@/lib/actions"
2020
import { createUrlSchema } from "@/lib/validations"
2121
import { RandomText } from "./random-text"
22+
import { env } from "@/env";
2223

2324
interface CreateUrlDialogProps {
2425
open: boolean
@@ -111,7 +112,7 @@ export function CreateUrlDialog({
111112
<p className="text-xs">Preview: </p>
112113
<div className="text-sm p-4 border rounded-md border-border mb-4 mt-1 flex flex-col gap-1 bg-muted/50 text-muted-foreground">
113114
<p className="font-mono mx-auto">
114-
https://polinet.cc/
115+
https://${env.DOMAIN}/
115116
{isRandom ? (
116117
<RandomText generate={randomCode} />
117118
) : (

src/components/dashboard.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ import {
3131
TableHeader,
3232
TableRow,
3333
} from "@/components/ui/table"
34+
import { env } from "@/env";
3435
import { useUrls } from "@/hooks/urls"
3536
import type { UrlRecord, UrlsQueryParams } from "@/lib/schemas"
36-
import { copyToClipboard } from "@/lib/utils"
37+
import {
38+
copyToClipboard, makeShortUrl} from "@/lib/utils"
3739
import { CreateUrlDialog } from "./create-url-dialog"
3840
import { type EditDialogState, EditUrlDialog } from "./edit-url-dialog"
3941
import { PaginationControls } from "./pagination"
@@ -120,7 +122,7 @@ export function Dashboard() {
120122
<div className="flex items-center gap-4">
121123
<Image src={logo} alt="PoliNetwork Logo" className="h-16 w-16" />
122124
<div className="gap-2">
123-
<h1 className="text-3xl font-bold">polinet.cc</h1>
125+
<h1 className="text-3xl font-bold">${env.DOMAIN}</h1>
124126
<p className="text-muted-foreground max-md:text-sm">
125127
PoliNetwork's URL shortener dashboard
126128
</p>
@@ -222,7 +224,7 @@ export function Dashboard() {
222224
key={url.id}
223225
url={url}
224226
onCopy={(url) =>
225-
copyToClipboard(`https://polinet.cc/${url.short_code}`)
227+
copyToClipboard(makeShortUrl(url))
226228
}
227229
onDelete={(url) => handleDelete(url.short_code)}
228230
onEdit={(url) => setEditDialog({ open: true, url })}
@@ -249,7 +251,7 @@ export function Dashboard() {
249251
key={url.id}
250252
url={url}
251253
onCopy={(url) =>
252-
copyToClipboard(`https://polinet.cc/${url.short_code}`)
254+
copyToClipboard(makeShortUrl(url))
253255
}
254256
onDelete={(url) => handleDelete(url.short_code)}
255257
onEdit={(url) => setEditDialog({ open: true, url })}

src/components/edit-url-dialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { Label } from "@/components/ui/label"
1818
import { editUrl } from "@/lib/actions"
1919
import type { UrlRecord } from "@/lib/schemas"
2020
import { editUrlSchema } from "@/lib/validations"
21+
import { makeShortUrl } from "@/lib/utils";
2122

2223
export type EditDialogState =
2324
| {
@@ -67,7 +68,7 @@ export function EditUrlDialog({
6768
<DialogHeader>
6869
<DialogTitle>Edit Short URL</DialogTitle>
6970
<DialogDescription>
70-
Update the destination URL for polinet.cc/{state.url.short_code}.
71+
Update the destination URL for {makeShortUrl(state.url)}.
7172
</DialogDescription>
7273
</DialogHeader>
7374
<form {...getFormProps(form, {})} action={action}>

src/components/qr-code-dialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
DialogTitle,
2121
} from "./ui/dialog"
2222
import { Tabs, TabsList, TabsTrigger } from "./ui/tabs"
23+
import { makeShortUrl } from "@/lib/utils";
2324

2425
export interface QrCodeDialogProps {
2526
open: boolean
@@ -48,7 +49,7 @@ export function QrCodeDialog({ open, url, onOpenChange }: QrCodeDialogProps) {
4849
}
4950

5051
if (!url) return null
51-
const shortUrl = `https://polinet.cc/${url.short_code}`
52+
const shortUrl = makeShortUrl(url)
5253

5354
return (
5455
<Dialog open={open} onOpenChange={onOpenChange}>

src/components/url-record-row.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
Trash2,
1010
} from "lucide-react"
1111
import type { UrlRecord } from "@/lib/schemas"
12-
import { copyToClipboard } from "@/lib/utils"
12+
import { makeShortUrl,
13+
copyToClipboard } from "@/lib/utils"
1314
import { Button } from "./ui/button"
1415
import { TableCell, TableRow } from "./ui/table"
1516

@@ -28,6 +29,7 @@ export function MobileRow({
2829
onEdit,
2930
onQrCode,
3031
}: UrlRecordRowProps) {
32+
const shortUrl = makeShortUrl(url)
3133
return (
3234
<div className="flex flex-col gap-1 border rounded-md py-2 px-4">
3335
<div className="flex justify-start gap-2 items-center">
@@ -38,12 +40,12 @@ export function MobileRow({
3840
)}
3941

4042
<a
41-
href={`https://polinet.cc/${url.short_code}`}
43+
href={shortUrl}
4244
target="_blank"
4345
rel="noopener noreferrer"
4446
className="text-blue-400 hover:underline font-mono"
4547
>
46-
polinet.cc/{url.short_code}
48+
{shortUrl}
4749
</a>
4850
<Button variant="ghost" size="icon" onClick={() => onCopy(url)}>
4951
<Copy />
@@ -92,6 +94,7 @@ export function MobileRow({
9294
}
9395

9496
export function UrlRecordRow({ url, ...props }: UrlRecordRowProps) {
97+
const shortUrl = makeShortUrl(url)
9598
return (
9699
<TableRow key={url.id} className="max-sm:hidden">
97100
<TableCell>
@@ -104,12 +107,12 @@ export function UrlRecordRow({ url, ...props }: UrlRecordRowProps) {
104107
<TableCell>
105108
<div className="flex items-center gap-2">
106109
<a
107-
href={`https://polinet.cc/${url.short_code}`}
110+
href={shortUrl}
108111
target="_blank"
109112
rel="noopener noreferrer"
110113
className="text-blue-400 hover:underline font-mono"
111114
>
112-
polinet.cc/{url.short_code}
115+
{shortUrl}
113116
</a>
114117
<Button variant="ghost" size="icon" onClick={() => props.onCopy(url)}>
115118
<Copy />

src/env.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export const env = createEnv({
1010
NODE_ENV: z.enum(["development", "production"]).default("development"),
1111
// PUBLIC_URL: z.string().default(`https://polinet.cc`),
1212
// LOG_LEVEL: z.string().default("DEBUG"),
13+
DOMAIN: z.string().default(`polinet.cc`).describe("This is the domain to use as shortener. API available at /api and Admin dashboard at /admin"),
14+
1315

1416
DB_HOST: z.string().min(1),
1517
DB_PORT: z.coerce.number().min(1).max(65535).default(5432),
@@ -21,6 +23,7 @@ export const env = createEnv({
2123

2224
runtimeEnv: {
2325
PORT: process.env.PORT,
26+
DOMAIN: process.env.DOMAIN,
2427
DB_HOST: process.env.DB_HOST,
2528
DB_PORT: process.env.DB_PORT,
2629
DB_USER: process.env.DB_USER,

src/lib/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { type ClassValue, clsx } from "clsx"
22
import { toast } from "sonner"
33
import { twMerge } from "tailwind-merge"
4+
import { env } from "@/env";
5+
import type { UrlRecord } from "./schemas";
46

57
export function cn(...inputs: ClassValue[]) {
68
return twMerge(clsx(inputs))
@@ -33,3 +35,7 @@ export const copyToClipboard = async (text: string) => {
3335
toast.error("Failed to copy to clipboard")
3436
}
3537
}
38+
39+
export function makeShortUrl(url: UrlRecord): string {
40+
return `https://${env.DOMAIN}/${url.short_code}`
41+
}

0 commit comments

Comments
 (0)