diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e69de29 diff --git a/app/api/url/[shortCode]/route.ts b/app/api/url/[shortCode]/route.ts index 92eb6d3..1e71b8e 100644 --- a/app/api/url/[shortCode]/route.ts +++ b/app/api/url/[shortCode]/route.ts @@ -1,17 +1,27 @@ -import { NextResponse } from 'next/server'; -import { getLongUrl, getUrlStats } from '@/lib/db'; +import { NextResponse } from 'next/server' +import { getLongUrl, getUrlStats } from '@/lib/db' export async function GET( request: Request, { params }: { params: { shortCode: string } } ) { - const { longUrl, expired } = getLongUrl(params.shortCode); - const stats = getUrlStats(params.shortCode); + try { + const { longUrl, expired } = getLongUrl(params.shortCode) + const stats = getUrlStats(params.shortCode) - if (longUrl) { - return NextResponse.json({ longUrl, expired, stats }); - } else { - return NextResponse.json({ longUrl: null, expired, stats: null }, { status: 404 }); + if (!longUrl) { + return NextResponse.json( + { error: 'URL not found', expired }, + { status: 404 } + ) + } + + return NextResponse.json({ longUrl, expired, stats }) + } catch (error) { + console.error('Error fetching URL:', error) + return NextResponse.json( + { error: 'Internal server error' }, + { status: 500 } + ) } } - diff --git a/app/layout.tsx b/app/layout.tsx index a36cde0..acce447 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -14,8 +14,8 @@ const geistMono = localFont({ }); export const metadata: Metadata = { - title: "Create Next App", - description: "Generated by create next app", + title: "Url Shortener", + description: "缩短你的长链接!", }; export default function RootLayout({ @@ -24,7 +24,7 @@ export default function RootLayout({ children: React.ReactNode; }>) { return ( - +
diff --git a/app/page.tsx b/app/page.tsx index 9c4ec43..54c5e58 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -7,11 +7,12 @@ export default function Home() {Short links now include visit tracking and expiration!
+如果您需要云服务器,欢迎使用雨云,性价比超高!
+注册时填写优惠码 cat ,享更多优惠!
- Report abusive content to:{' '} - - report@example.com + 违规举报:{' '} + + i@mei.lv
+ 请求的短链接不存在或已过期。 +
+- {expired - ? 'Sorry, this short link has expired.' - : 'The requested short link does not exist.'} -
- -- Report abusive content:{' '} - - report@example.com - -
-
- Short URL: {`${process.env.NEXT_PUBLIC_BASE_URL}/s/${shortCode}`}
+
+ 少女祈祷中...
- Visits: {visits} -
-- Destination: {longUrl} -
-- Expires at: {expiresAt ? new Date(expiresAt).toLocaleString() : 'Never'} -
-- This link will take you to an external website. We are not responsible for the content - of external sites. Please proceed with caution. -
-- This could be your ad! Contact us for advertising opportunities. -
+ + + +我们的位置
+{`${process.env.NEXT_PUBLIC_BASE_URL}/s/${params.shortCode}`}
+访问量
+{data.stats.visits}
+目的地
+{data.longUrl}
+过期时间
++ {data.stats.expiresAt ? new Date(data.stats.expiresAt).toLocaleString() : 'Never'} +
++ 本链接将会为您跳转一个外部网站,我们不对这些外部网站的内容负责,请谨慎访问。 +
++ 雨云,高性价比的云服务商 + 立即购买! +
+- Report abusive content:{' '} - - report@example.com + 违规举报:{' '} + + i@mei.lv