Files
cozsweet-frontend-nextjs/next.config.ts
T
admin 0d5c416cba fix(images): allowlist Facebook avatar hosts in next/image remotePatterns
Facebook OAuth login returns avatar URLs from
platform-lookaside.fbsbx.com (and occasionally graph.facebook.com).
next/image's optimizer rejects these with 400 Bad Request when they
are not in the allowlist, so chat/sidebar/subscription avatar
<Image> components all fail to render.

Add images.remotePatterns entries for both hosts. Three <Image>
consumers (message-avatar, user-header, subscription-user-row) need
no changes — they all pass the avatarUrl through verbatim and will
work once the optimizer accepts the host.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-17 11:14:24 +08:00

47 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { NextConfig } from "next";
import { withSerwist } from "@serwist/turbopack";
/**
* Next.js 16 临时绕过 `/_global-error` prerender 的 workStore bug
* 标记根 layout 不参与静态预渲染(global-error 会在请求时渲染)
* https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config
*
* 默认部署模型:`.next/` + `public/` + `next start`(或 Vercel 零配置)
* - `pnpm build` 产出 .next/(含 build manifest / chunks / 路由表 / 静态预渲染)
* - 脚本侧:scripts/deploy/_deploy_lib.sh 同步 .next/ + public/
* - 服务器启动:`cd <path> && next start -H 0.0.0.0 -p 3000`
* 或用 PM2`pm2 start "next start" --name cozsweet`
*
* PWA 集成:`@serwist/turbopack` 在 build 阶段用 esbuild 编译 `src/app/sw.ts` 源文件。
* - Turbopack 原生支持 —— 不再需要 `--webpack` flag
* - SW 通过 Serwist Route Handlersrc/app/serwist/[[...slug]]/route.ts)在 `/serwist/sw.js` 服务
* - 客户端注册走 `<SerwistProvider swUrl="/serwist/sw.js">`(替代旧的 <SwRegister />
*
* 历史:
* - 之前用 @ducanh2912/next-pwawebpack-only),被迫用 `--webpack` 退 Turbopack
* - 切到 @serwist/turbopack 后拿回 Turbopack 的 dev/build 性能
*/
const nextConfig: NextConfig = {
experimental: {
// 关闭静态优化以规避 16.2.7 global-error prerender bug
staticGenerationRetryCount: 0,
},
images: {
// Facebook OAuth 登录后,`picture.type(large)` 返回
// platform-lookaside.fbsbx.com/platform/profilepic/?asid=...&hash=...
// 该 URL 是**下载链接**而非可缓存图片,next/image 优化器需要显式 allowlist。
// graph.facebook.com 兜底:Graph 偶尔返回直链头像 / OG 图。
remotePatterns: [
{
protocol: "https",
hostname: "platform-lookaside.fbsbx.com",
},
{
protocol: "https",
hostname: "graph.facebook.com",
},
],
},
};
export default withSerwist(nextConfig);