Skip to content

Commit 3d43a68

Browse files
committed
feat: update to Next.js 15.6.0-canary.27 and enhance HomePage metadata
- Upgraded Next.js version in package.json and pnpm-lock.yaml to 15.6.0-canary.27. - Added metadata to HomePage for improved SEO and social sharing, including Open Graph and Twitter card data. - Implemented a new API route for managing likes, including GET and POST methods for fetching and incrementing like counts. - Updated LikeWrapper component to fetch initial likes from the new API and handle like increments through API calls. - Added a new image for Open Graph sharing.
1 parent 4cc0f18 commit 3d43a68

6 files changed

Lines changed: 145 additions & 47 deletions

File tree

demo/app/api/likes/route.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { NextResponse } from 'next/server'
2+
3+
import { getRedis } from '@/lib/redis'
4+
import { getServerRealtime } from '@/lib/realtime/server'
5+
6+
export const dynamic = 'force-dynamic'
7+
8+
export async function GET() {
9+
try {
10+
const redis = getRedis()
11+
const count = await redis.get('demo:likes')
12+
return NextResponse.json({ count: count ? Number(count) : 0 })
13+
} catch (error) {
14+
console.error('Failed to get likes:', error)
15+
return NextResponse.json(
16+
{ status: 'error', message: 'Internal server error' },
17+
{ status: 500 }
18+
)
19+
}
20+
}
21+
22+
export async function POST() {
23+
try {
24+
const redis = getRedis()
25+
26+
const newCount = await redis.incr('demo:likes')
27+
28+
const realtime = getServerRealtime()
29+
await realtime.push('demo:likes:updated', { count: newCount })
30+
31+
return NextResponse.json({ count: newCount })
32+
} catch (error) {
33+
console.error('Failed to increment likes:', error)
34+
return NextResponse.json(
35+
{ status: 'error', message: 'Internal server error' },
36+
{ status: 500 }
37+
)
38+
}
39+
}

demo/app/page.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Metadata } from "next";
12
import {
23
codeExampleToJsx,
34
dockerCommand,
@@ -22,6 +23,48 @@ import { RiDiscordFill, RiGithubFill } from "@remixicon/react";
2223
import Link from "next/link";
2324
import LikeWrapper from "@/components/like-wrapper";
2425

26+
export const metadata: Metadata = {
27+
title: "Type-safe live updates in minutes | Impulse Realtime",
28+
description: "Zero-config SSE. Shared types. Simple client & server helpers.",
29+
keywords: [
30+
"Impulse Realtime",
31+
"type-safe live updates",
32+
"SSE",
33+
"real-time API",
34+
"shared types",
35+
],
36+
alternates: {
37+
canonical: "https://realtime.impulselab.ai",
38+
},
39+
openGraph: {
40+
title: "Type-safe live updates in minutes | Impulse Realtime",
41+
description:
42+
"Zero-config SSE. Shared types. Simple client & server helpers.",
43+
url: "https://realtime.impulselab.ai",
44+
images: [
45+
{
46+
url: "/realtime-og.png",
47+
width: 1200,
48+
height: 630,
49+
alt: "Type-safe live updates in minutes",
50+
},
51+
],
52+
},
53+
twitter: {
54+
title: "Type-safe live updates in minutes | Impulse Realtime",
55+
description:
56+
"Zero-config SSE. Shared types. Simple client & server helpers.",
57+
images: [
58+
{
59+
url: "/realtime-og.png",
60+
width: 1200,
61+
height: 630,
62+
alt: "Type-safe live updates in minutes",
63+
},
64+
],
65+
},
66+
};
67+
2568
export default async function HomePage() {
2669
return (
2770
<main className="border-x border-gray-700 min-h-screen mx-auto w-[90vw] max-w-4xl pt-[10vh]">

demo/components/like-wrapper.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use client";
22

33
import { useEffect, useState } from "react";
4-
import { getInitialLikes, incrementLikesAction } from "@/app/actions";
54
import LikeButton from "./like-button";
65

76
export default function LikeWrapper() {
@@ -11,7 +10,11 @@ export default function LikeWrapper() {
1110
useEffect(() => {
1211
const fetchInitialLikes = async () => {
1312
try {
14-
const count = await getInitialLikes();
13+
const response = await fetch('/api/likes');
14+
if (!response.ok) {
15+
throw new Error(`HTTP error! status: ${response.status}`);
16+
}
17+
const { count } = await response.json();
1518
setInitialCount(count);
1619
} catch (error) {
1720
console.error("Failed to fetch initial likes:", error);
@@ -24,13 +27,26 @@ export default function LikeWrapper() {
2427
fetchInitialLikes();
2528
}, []);
2629

30+
const handleLike = async () => {
31+
try {
32+
const response = await fetch('/api/likes', {
33+
method: 'POST',
34+
});
35+
if (!response.ok) {
36+
throw new Error(`HTTP error! status: ${response.status}`);
37+
}
38+
} catch (error) {
39+
console.error("Failed to increment likes:", error);
40+
}
41+
};
42+
2743
if (!isLoaded) {
2844
return (
29-
<LikeButton initialCount={0} onLike={incrementLikesAction} />
45+
<LikeButton initialCount={0} onLike={handleLike} />
3046
);
3147
}
3248

3349
return (
34-
<LikeButton initialCount={initialCount} onLike={incrementLikesAction} />
50+
<LikeButton initialCount={initialCount} onLike={handleLike} />
3551
);
3652
}

demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"ioredis": "^5.7.0",
1717
"lucide-react": "^0.544.0",
1818
"motion": "^12.23.19",
19-
"next": "15.5.3",
19+
"next": "15.6.0-canary.27",
2020
"postcss": "^8.5.6",
2121
"react": "19.1.0",
2222
"react-dom": "19.1.0",

demo/public/realtime-og.png

793 KB
Loading

pnpm-lock.yaml

Lines changed: 42 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)