Skip to content

Commit 1e4e4d5

Browse files
committed
feat: 更新 Cloudflare Pages 配置,优化动态渲染设置并调整数据库名称
1 parent ba153df commit 1e4e4d5

File tree

9 files changed

+21
-42
lines changed

9 files changed

+21
-42
lines changed

next.config.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@
22
/* eslint-disable @typescript-eslint/no-var-requires */
33
const nextConfig = {
44
// For Cloudflare Pages, use 'export' instead of 'standalone'
5-
output: process.env.CLOUDFLARE_PAGES === '1' ? 'export' : 'standalone',
5+
// output: process.env.CLOUDFLARE_PAGES === '1' ? 'export' : 'standalone',
66

77
eslint: {
88
dirs: ['src'],
99
},
1010

1111
reactStrictMode: false,
1212
swcMinify: true,
13-
14-
// Disable server components for better Cloudflare Pages compatibility
15-
experimental: {
16-
serverActions: false,
17-
serverComponentsExternalPackages: [],
18-
},
1913

2014
// Uncoment to add domain whitelist
2115
images: {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"postbuild": "echo 'Build completed - sitemap generation disabled'",
2121
"prepare": "husky install",
2222
"pages:build": "pnpm gen:runtime && pnpm gen:manifest && next build && npx @cloudflare/next-on-pages --experimental-minify",
23-
"cloudflare:build": "set CLOUDFLARE_PAGES=1&& npm run gen:runtime && npm run gen:manifest && next build",
23+
"cloudflare:build": "npm run gen:runtime && npm run gen:manifest && npm run build",
2424
"test:live": "node scripts/test-live-tv.js",
2525
"deploy:check": "node scripts/deployment-check.js"
2626
},

public/sw.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/api/admin/live/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { getStorage } from '@/lib/db';
44
import { fetchAndParseM3U, isValidM3UUrl } from '@/lib/m3u-parser';
55
import { LiveConfig } from '@/lib/types';
66

7-
// 强制动态渲染
8-
export const runtime = 'edge';
9-
export const dynamic = 'force-dynamic';
7+
// 针对不同部署模式的配置
8+
export const runtime = process.env.CLOUDFLARE_PAGES === '1' ? 'edge' : 'nodejs';
9+
export const dynamic = process.env.CLOUDFLARE_PAGES === '1' ? 'force-dynamic' : 'auto';
1010

1111
// 验证管理员权限的中间件
1212
async function checkAdminAuth(request: NextRequest) {

src/app/api/live/channels/route.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import { NextRequest, NextResponse } from 'next/server';
33
import { getStorage } from '@/lib/db';
44
import { fetchAndParseM3U } from '@/lib/m3u-parser';
55

6-
// 强制动态渲染
7-
export const runtime = 'edge';
8-
export const dynamic = 'force-dynamic';
6+
// 针对不同部署模式的配置
7+
export const runtime = process.env.CLOUDFLARE_PAGES === '1' ? 'edge' : 'nodejs';
98

109
export async function GET(request: NextRequest) {
1110
try {
12-
const { searchParams } = new URL(request.url);
13-
const sourceKey = searchParams.get('source');
11+
const url = new URL(request.url);
12+
const sourceKey = url.searchParams.get('source');
1413

1514
if (!sourceKey) {
1615
return NextResponse.json({ error: '缺少直播源参数' }, { status: 400 });

src/app/api/live/sources/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { NextRequest, NextResponse } from 'next/server';
22

33
import { getStorage } from '@/lib/db';
44

5-
// 强制动态渲染
6-
export const runtime = 'edge';
7-
export const dynamic = 'force-dynamic';
5+
// 针对不同部署模式的配置
6+
export const runtime = process.env.CLOUDFLARE_PAGES === '1' ? 'edge' : 'nodejs';
7+
export const dynamic = process.env.CLOUDFLARE_PAGES === '1' ? 'force-dynamic' : 'auto';
88

99
export async function GET(_request: NextRequest) {
1010
try {

src/app/live/sources/page.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ import { useCallback, useEffect, useState } from 'react';
55

66
import PageLayout from '@/components/PageLayout';
77

8-
// 强制动态渲染
9-
export const dynamic = 'force-dynamic';
10-
118
interface LiveSource {
129
key: string;
1310
name: string;

src/components/PageLayout.tsx

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Clover, Film, Home, Search, Tv } from 'lucide-react';
22
import Link from 'next/link';
3-
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
3+
import { usePathname, useRouter } from 'next/navigation';
44
import { useCallback, useEffect, useState } from 'react';
55

66
import { BackButton } from './BackButton';
@@ -19,25 +19,14 @@ interface PageLayoutProps {
1919
const TopNavbar = ({ activePath = '/' }: { activePath?: string }) => {
2020
const router = useRouter();
2121
const pathname = usePathname();
22-
const searchParams = useSearchParams();
2322
const { siteName } = useSite();
2423

2524
const [active, setActive] = useState(activePath);
2625

2726
useEffect(() => {
28-
// 优先使用传入的 activePath
29-
if (activePath) {
30-
setActive(activePath);
31-
} else {
32-
// 否则使用当前路径
33-
const getCurrentFullPath = () => {
34-
const queryString = searchParams.toString();
35-
return queryString ? `${pathname}?${queryString}` : pathname;
36-
};
37-
const fullPath = getCurrentFullPath();
38-
setActive(fullPath);
39-
}
40-
}, [activePath, pathname, searchParams]);
27+
// 优先使用传入的 activePath,否则使用当前路径
28+
setActive(activePath || pathname);
29+
}, [activePath, pathname]);
4130

4231
const handleSearchClick = useCallback(() => {
4332
router.push('/search');

wrangler.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ vars = { STORAGE_TYPE = "d1" }
77

88
[[env.production.d1_databases]]
99
binding = "DB"
10-
database_name = "katelyatv-production"
11-
database_id = "" # Production
10+
database_name = "katelyatv"
11+
database_id = "c312fe33-7600-4226-b948-6aed7e76f0ad"
1212

1313
[env.preview]
1414
vars = { STORAGE_TYPE = "d1" }
1515

1616
[[env.preview.d1_databases]]
1717
binding = "DB"
18-
database_name = "katelyatv-preview"
19-
database_id = "" # Preview
18+
database_name = "katelyatv"
19+
database_id = "c312fe33-7600-4226-b948-6aed7e76f0ad"

0 commit comments

Comments
 (0)