🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat(next): unify asset base URL and namespace app static dirs (#18221)
Innei50548e7d3192
diff --git a/docs/self-hosting/environment-variables/basic.mdx b/docs/self-hosting/environment-variables/basic.mdxindex dba83761da4..24dcb26e2f4 100644--- a/docs/self-hosting/environment-variables/basic.mdx+++ b/docs/self-hosting/environment-variables/basic.mdx@@ -210,10 +210,26 @@ SSRF_ALLOW_IP_ADDRESS_LIST=192.168.1.100,10.0.0.50- Allow access to internal API gateway: `10.0.0.50`- Allow access to internal documentation server: `172.16.0.10`-### `NEXT_PUBLIC_ASSET_PREFIX`+### `ASSET_BASE_URL`- Type: Optional-- Description: The path access prefix for static resources can be set to the URL for CDN access. For more details, please refer to: [assetPrefix](https://nextjs.org/docs/app/api-reference/config/next-config-js/assetPrefix)+- Description: Base URL for build output (Next.js static assets and the SPA bundles). Set it to a CDN or object-storage origin to serve build assets from somewhere other than the app itself. It maps to Next.js [assetPrefix](https://nextjs.org/docs/app/api-reference/config/next-config-js/assetPrefix). Leave it unset to serve everything from the app origin.+- Default: -+- Example: `https://cdn.example.com`++<Callout type={'warning'}>+ When this points at a different origin than the app, that host **must** respond with an+ `Access-Control-Allow-Origin` header covering your app's origin. Once an asset base URL is+ configured, LobeHub emits `crossorigin` on the generated `<script>` and `<link>` tags — a host+ without the header makes the browser refuse to execute those assets, leaving a blank page. It also+ means script errors from those files reach error monitoring with a real stack instead of an opaque+ `Script error.` frame.+</Callout>++### `NEXT_PUBLIC_ASSET_PREFIX`++- Type: Optional, **deprecated** — use `ASSET_BASE_URL` instead+- Description: Previous name for `ASSET_BASE_URL`. Still used as a fallback when `ASSET_BASE_URL` is unset, and carries the same cross-origin requirement described above.- Default: -- Example: `https://cdn.example.com`diff --git a/docs/self-hosting/environment-variables/basic.zh-CN.mdx b/docs/self-hosting/environment-variables/basic.zh-CN.mdxindex 153bc1fa2c3..f78852f95e2 100644--- a/docs/self-hosting/environment-variables/basic.zh-CN.mdx+++ b/docs/self-hosting/environment-variables/basic.zh-CN.mdx@@ -205,10 +205,24 @@ SSRF_ALLOW_IP_ADDRESS_LIST=192.168.1.100,10.0.0.50- 允许访问内网 API 网关:`10.0.0.50`- 允许访问内网文档服务器:`172.16.0.10`-### `NEXT_PUBLIC_ASSET_PREFIX`+### `ASSET_BASE_URL`- 类型:可选-- 描述:静态资源的路径访问前缀,你可以设置为 CDN 访问的 URL,具体可参考: [assetPrefix](https://nextjs.org/docs/app/api-reference/config/next-config-js/assetPrefix)+- 描述:构建产物(Next.js 静态资源与 SPA 包)的基础 URL。设置为 CDN 或对象存储的域名,即可让构建产物不再由应用自身分发。它对应 Next.js 的 [assetPrefix](https://nextjs.org/docs/app/api-reference/config/next-config-js/assetPrefix)。不设置时,所有资源仍由应用同源提供。+- 默认值:-+- 示例:`https://cdn.example.com`++<Callout type={'warning'}>+ 当它指向与应用不同的域名时,该资源域名**必须**返回覆盖应用域名的 `Access-Control-Allow-Origin`+ 响应头。一旦配置了资源基础 URL,LobeHub 会在生成的 `<script>` 与 `<link>` 标签上带出+ `crossorigin`;缺少该响应头会让浏览器拒绝执行这些资源,页面直接白屏。它同时也让这些文件的脚本报错能带着真实堆栈进入错误监控,而不是一条无信息的+ `Script error.`。+</Callout>++### `NEXT_PUBLIC_ASSET_PREFIX`++- 类型:可选,**已废弃** —— 请改用 `ASSET_BASE_URL`+- 描述:`ASSET_BASE_URL` 的旧名称。在未设置 `ASSET_BASE_URL` 时仍会作为回退生效,并且同样受上述跨域要求约束。- 默认值:-- 示例:`https://cdn.example.com`diff --git a/packages/const/src/meta.ts b/packages/const/src/meta.tsindex da467328c12..d546c6a6111 100644--- a/packages/const/src/meta.ts+++ b/packages/const/src/meta.ts@@ -9,4 +9,4 @@ export const DEFAULT_BACKGROUND_COLOR = undefined;export const DEFAULT_AGENT_META: MetaData = {};export const DEFAULT_INBOX_TITLE = 'Lobe AI';export const DEFAULT_INBOX_AVATAR = BRANDING_LOGO_URL || '/avatars/lobe-ai.png';-export const DEFAULT_USER_AVATAR_URL = BRANDING_LOGO_URL || '/icons/icon-192x192.png';+export const DEFAULT_USER_AVATAR_URL = BRANDING_LOGO_URL || '/app-icons/icon-192x192.png';diff --git a/packages/const/src/url.ts b/packages/const/src/url.tsindex 8a1a33bb135..d03a802f6d6 100644--- a/packages/const/src/url.ts+++ b/packages/const/src/url.ts@@ -75,7 +75,7 @@ export const GROUP_CHAT_TOPIC_URL = (groupId: string, topicId: string) =>export const LIBRARY_URL = (id: string) => urlJoin('/resource/library', id);-export const imageUrl = (filename: string) => `/images/${filename}`;+export const imageUrl = (filename: string) => `/app-images/${filename}`;export const LOBE_URL_IMPORT_NAME = 'settings';diff --git a/public/icons/icon-192x192.maskable.png b/public/app-icons/icon-192x192.maskable.pngsimilarity index 100%rename from public/icons/icon-192x192.maskable.pngrename to public/app-icons/icon-192x192.maskable.pngdiff --git a/public/icons/icon-192x192.png b/public/app-icons/icon-192x192.pngsimilarity index 100%rename from public/icons/icon-192x192.pngrename to public/app-icons/icon-192x192.pngdiff --git a/public/icons/icon-512x512.maskable.png b/public/app-icons/icon-512x512.maskable.pngsimilarity index 100%rename from public/icons/icon-512x512.maskable.pngrename to public/app-icons/icon-512x512.maskable.pngdiff --git a/public/icons/icon-512x512.png b/public/app-icons/icon-512x512.pngsimilarity index 100%rename from public/icons/icon-512x512.pngrename to public/app-icons/icon-512x512.pngdiff --git a/public/images/agent-artwork-styles/style-clay.jpg b/public/app-images/agent-artwork-styles/style-clay.jpgsimilarity index 100%rename from public/images/agent-artwork-styles/style-clay.jpgrename to public/app-images/agent-artwork-styles/style-clay.jpgdiff --git a/public/images/agent-artwork-styles/style-geometric.jpg b/public/app-images/agent-artwork-styles/style-geometric.jpgsimilarity index 100%rename from public/images/agent-artwork-styles/style-geometric.jpgrename to public/app-images/agent-artwork-styles/style-geometric.jpgdiff --git a/public/images/agent-artwork-styles/style-pixel.jpg b/public/app-images/agent-artwork-styles/style-pixel.jpgsimilarity index 100%rename from public/images/agent-artwork-styles/style-pixel.jpgrename to public/app-images/agent-artwork-styles/style-pixel.jpgdiff --git a/public/images/agent-artwork-styles/style-sticker.jpg b/public/app-images/agent-artwork-styles/style-sticker.jpgsimilarity index 100%rename from public/images/agent-artwork-styles/style-sticker.jpgrename to public/app-images/agent-artwork-styles/style-sticker.jpgdiff --git a/public/images/agent-artwork-styles/style-watercolor.jpg b/public/app-images/agent-artwork-styles/style-watercolor.jpgsimilarity index 100%rename from public/images/agent-artwork-styles/style-watercolor.jpgrename to public/app-images/agent-artwork-styles/style-watercolor.jpgdiff --git a/public/images/agent_gateway_dark.webp b/public/app-images/agent_gateway_dark.webpsimilarity index 100%rename from public/images/agent_gateway_dark.webprename to public/app-images/agent_gateway_dark.webpdiff --git a/public/images/agent_gateway_light.webp b/public/app-images/agent_gateway_light.webpsimilarity index 100%rename from public/images/agent_gateway_light.webprename to public/app-images/agent_gateway_light.webpdiff --git a/public/images/banner_creator.png b/public/app-images/banner_creator.pngsimilarity index 100%rename from public/images/banner_creator.pngrename to public/app-images/banner_creator.pngdiff --git a/public/images/banner_market_modal.webp b/public/app-images/banner_market_modal.webpsimilarity index 100%rename from public/images/banner_market_modal.webprename to public/app-images/banner_market_modal.webpdiff --git a/public/images/chatmode_chat_dark.webp b/public/app-images/chatmode_chat_dark.webpsimilarity index 100%rename from public/images/chatmode_chat_dark.webprename to public/app-images/chatmode_chat_dark.webpdiff --git a/public/images/chatmode_chat_light.webp b/public/app-images/chatmode_chat_light.webpsimilarity index 100%rename from public/images/chatmode_chat_light.webprename to public/app-images/chatmode_chat_light.webpdiff --git a/public/images/chatmode_docs_dark.webp b/public/app-images/chatmode_docs_dark.webpsimilarity index 100%rename from public/images/chatmode_docs_dark.webprename to public/app-images/chatmode_docs_dark.webpdiff --git a/public/images/chatmode_docs_light.webp b/public/app-images/chatmode_docs_light.webpsimilarity index 100%rename from public/images/chatmode_docs_light.webprename to public/app-images/chatmode_docs_light.webpdiff --git a/public/images/community_footer_dark.webp b/public/app-images/community_footer_dark.webpsimilarity index 100%rename from public/images/community_footer_dark.webprename to public/app-images/community_footer_dark.webpdiff --git a/public/images/community_footer_light.webp b/public/app-images/community_footer_light.webpsimilarity index 100%rename from public/images/community_footer_light.webprename to public/app-images/community_footer_light.webpdiff --git a/public/images/community_header_dark.webp b/public/app-images/community_header_dark.webpsimilarity index 100%rename from public/images/community_header_dark.webprename to public/app-images/community_header_dark.webpdiff --git a/public/images/community_header_light.webp b/public/app-images/community_header_light.webpsimilarity index 100%rename from public/images/community_header_light.webprename to public/app-images/community_header_light.webpdiff --git a/public/images/empty_topic_dark.webp b/public/app-images/empty_topic_dark.webpsimilarity index 100%rename from public/images/empty_topic_dark.webprename to public/app-images/empty_topic_dark.webpdiff --git a/public/images/empty_topic_light.webp b/public/app-images/empty_topic_light.webpsimilarity index 100%rename from public/images/empty_topic_light.webprename to public/app-images/empty_topic_light.webpdiff --git a/public/images/mode_lite_dark.webp b/public/app-images/mode_lite_dark.webpsimilarity index 100%rename from public/images/mode_lite_dark.webprename to public/app-images/mode_lite_dark.webpdiff --git a/public/images/mode_lite_light.webp b/public/app-images/mode_lite_light.webpsimilarity index 100%rename from public/images/mode_lite_light.webprename to public/app-images/mode_lite_light.webpdiff --git a/public/images/mode_pro_dark.webp b/public/app-images/mode_pro_dark.webpsimilarity index 100%rename from public/images/mode_pro_dark.webprename to public/app-images/mode_pro_dark.webpdiff --git a/public/images/mode_pro_light.webp b/public/app-images/mode_pro_light.webpsimilarity index 100%rename from public/images/mode_pro_light.webprename to public/app-images/mode_pro_light.webpdiff --git a/public/images/screenshot_background.webp b/public/app-images/screenshot_background.webpsimilarity index 100%rename from public/images/screenshot_background.webprename to public/app-images/screenshot_background.webpdiff --git a/public/images/theme_auto.webp b/public/app-images/theme_auto.webpsimilarity index 100%rename from public/images/theme_auto.webprename to public/app-images/theme_auto.webpdiff --git a/public/images/theme_dark.webp b/public/app-images/theme_dark.webpsimilarity index 100%rename from public/images/theme_dark.webprename to public/app-images/theme_dark.webpdiff --git a/public/images/theme_light.webp b/public/app-images/theme_light.webpsimilarity index 100%rename from public/images/theme_light.webprename to public/app-images/theme_light.webpdiff --git a/src/app/manifest.ts b/src/app/manifest.tsindex caf3465d78a..b5bd064a978 100644--- a/src/app/manifest.ts+++ b/src/app/manifest.ts@@ -10,7 +10,7 @@ const manifest = async (): Promise<MetadataRoute.Manifest> => {icons: [{sizes: '192x192',- src: '/icons/icon-192x192.png',+ src: '/app-icons/icon-192x192.png',type: 'image/png',},],@@ -35,22 +35,22 @@ const manifest = async (): Promise<MetadataRoute.Manifest> => {{purpose: 'any',sizes: '192x192',- url: '/icons/icon-192x192.png',+ url: '/app-icons/icon-192x192.png',},{purpose: 'maskable',sizes: '192x192',- url: '/icons/icon-192x192.maskable.png',+ url: '/app-icons/icon-192x192.maskable.png',},{purpose: 'any',sizes: '512x512',- url: '/icons/icon-512x512.png',+ url: '/app-icons/icon-512x512.png',},{purpose: 'maskable',sizes: '512x512',- url: '/icons/icon-512x512.maskable.png',+ url: '/app-icons/icon-512x512.maskable.png',},],id: kebabCase(BRANDING_NAME),diff --git a/src/features/ChatInput/ActionBar/Plus/index.tsx b/src/features/ChatInput/ActionBar/Plus/index.tsxindex 0329e8afbad..48a2eafe655 100644--- a/src/features/ChatInput/ActionBar/Plus/index.tsx+++ b/src/features/ChatInput/ActionBar/Plus/index.tsx@@ -457,7 +457,9 @@ const usePlusMenuItems = ({ close }: { close: () => void }): ActionDropdownMenuI<imgalt=""className="cover"- src={isDark ? '/images/agent_gateway_dark.webp' : '/images/agent_gateway_light.webp'}+ src={+ isDark ? '/app-images/agent_gateway_dark.webp' : '/app-images/agent_gateway_light.webp'+ }/><div className="body"><div className="title">{t('gatewayMode.cardTitle')}</div>diff --git a/src/layout/AuthProvider/MarketAuth/MarketAuthConfirmModal.tsx b/src/layout/AuthProvider/MarketAuth/MarketAuthConfirmModal.tsxindex 26ea5343bf3..469e4f199c6 100644--- a/src/layout/AuthProvider/MarketAuth/MarketAuthConfirmModal.tsx+++ b/src/layout/AuthProvider/MarketAuth/MarketAuthConfirmModal.tsx@@ -17,14 +17,14 @@ const styles = createStaticStyles(({ css }) => ({container: css`padding-block-start: 32px;- background-image: url('/images/community_header_light.webp');+ background-image: url('/app-images/community_header_light.webp');background-repeat: no-repeat;background-position: 400% 0;background-size: 400px auto;background-blend-mode: multiply;`,container_dark: css`- background-image: url('/images/community_header_dark.webp');+ background-image: url('/app-images/community_header_dark.webp');background-blend-mode: screen;`,}));diff --git a/src/libs/next/config/define-config.test.ts b/src/libs/next/config/define-config.test.tsindex 8e58164f24d..8f4f2ca9f03 100644--- a/src/libs/next/config/define-config.test.ts+++ b/src/libs/next/config/define-config.test.ts@@ -1,9 +1,80 @@-import { describe, expect, it } from 'vitest';+import { afterEach, describe, expect, it } from 'vitest';import { defineConfig } from './define-config';describe('defineConfig', () => {+ const originalAssetBaseUrl = process.env.ASSET_BASE_URL;+ const originalLegacyPrefix = process.env.NEXT_PUBLIC_ASSET_PREFIX;++ afterEach(() => {+ if (originalAssetBaseUrl === undefined) delete process.env.ASSET_BASE_URL;+ else process.env.ASSET_BASE_URL = originalAssetBaseUrl;++ if (originalLegacyPrefix === undefined) delete process.env.NEXT_PUBLIC_ASSET_PREFIX;+ else process.env.NEXT_PUBLIC_ASSET_PREFIX = originalLegacyPrefix;+ });+it('disables Next.js agent rule injection', () => {expect(defineConfig({}).agentRules).toBe(false);});++ describe('crossOrigin', () => {+ it('stays unset when no asset prefix is configured', () => {+ delete process.env.ASSET_BASE_URL;+ delete process.env.NEXT_PUBLIC_ASSET_PREFIX;++ expect(defineConfig({}).crossOrigin).toBeUndefined();+ });++ it('is anonymous when ASSET_BASE_URL is set', () => {+ process.env.ASSET_BASE_URL = 'https://assets.example.com';+ delete process.env.NEXT_PUBLIC_ASSET_PREFIX;++ expect(defineConfig({}).crossOrigin).toBe('anonymous');+ });++ it('is anonymous when only the deprecated NEXT_PUBLIC_ASSET_PREFIX is set', () => {+ delete process.env.ASSET_BASE_URL;+ process.env.NEXT_PUBLIC_ASSET_PREFIX = 'https://legacy.example.com';++ expect(defineConfig({}).crossOrigin).toBe('anonymous');+ });+ });++ describe('assetPrefix', () => {+ it('is undefined when no env is set', () => {+ delete process.env.ASSET_BASE_URL;+ delete process.env.NEXT_PUBLIC_ASSET_PREFIX;++ expect(defineConfig({}).assetPrefix).toBeUndefined();+ });++ it('derives from ASSET_BASE_URL, stripping a trailing slash', () => {+ process.env.ASSET_BASE_URL = 'https://assets.example.com/';+ delete process.env.NEXT_PUBLIC_ASSET_PREFIX;++ expect(defineConfig({}).assetPrefix).toBe('https://assets.example.com');+ });++ it('falls back to the deprecated NEXT_PUBLIC_ASSET_PREFIX', () => {+ delete process.env.ASSET_BASE_URL;+ process.env.NEXT_PUBLIC_ASSET_PREFIX = 'https://legacy.example.com';++ expect(defineConfig({}).assetPrefix).toBe('https://legacy.example.com');+ });++ it('strips a trailing slash from the deprecated NEXT_PUBLIC_ASSET_PREFIX too', () => {+ delete process.env.ASSET_BASE_URL;+ process.env.NEXT_PUBLIC_ASSET_PREFIX = 'https://legacy.example.com/';++ expect(defineConfig({}).assetPrefix).toBe('https://legacy.example.com');+ });++ it('prefers ASSET_BASE_URL over the deprecated key', () => {+ process.env.ASSET_BASE_URL = 'https://assets.example.com';+ process.env.NEXT_PUBLIC_ASSET_PREFIX = 'https://legacy.example.com';++ expect(defineConfig({}).assetPrefix).toBe('https://assets.example.com');+ });+ });});diff --git a/src/libs/next/config/define-config.ts b/src/libs/next/config/define-config.tsindex d4281db5458..97ea08116fe 100644--- a/src/libs/next/config/define-config.ts+++ b/src/libs/next/config/define-config.ts@@ -49,13 +49,19 @@ export function defineConfig(config: CustomNextConfig) {},};- const assetPrefix = process.env.NEXT_PUBLIC_ASSET_PREFIX;+ const assetPrefix = (process.env.ASSET_BASE_URL || process.env.NEXT_PUBLIC_ASSET_PREFIX)?.replace(+ /\/+$/,+ '',+ );const nextConfig: NextConfig = {...(isStandaloneMode ? standaloneConfig : {}),// Stop `next dev` from auto-injecting the nextjs-agent-rules block into AGENTS.md.agentRules: false,assetPrefix,+ // Gated, not unconditional: an asset host that omits Access-Control-Allow-Origin+ // turns every tag into one the browser refuses to execute. Same-origin needs no opt-in.+ crossOrigin: assetPrefix ? 'anonymous' : undefined,compiler: {emotion: true,@@ -111,7 +117,7 @@ export function defineConfig(config: CustomNextConfig) {value: 'public, max-age=31536000, immutable',},],- source: '/icons/(.*).(png|jpe?g|gif|svg|ico|webp)',+ source: '/app-icons/(.*).(png|jpe?g|gif|svg|ico|webp)',},{headers: [@@ -128,7 +134,7 @@ export function defineConfig(config: CustomNextConfig) {value: 'public, max-age=31536000, immutable',},],- source: '/images/(.*).(png|jpe?g|gif|svg|ico|webp)',+ source: '/app-images/(.*).(png|jpe?g|gif|svg|ico|webp)',},{headers: [diff --git a/src/routes/(main)/community/(list)/(home)/features/CreatorRewardBanner.tsx b/src/routes/(main)/community/(list)/(home)/features/CreatorRewardBanner.tsxindex 6a0b43f2fca..a303b5c8e34 100644--- a/src/routes/(main)/community/(list)/(home)/features/CreatorRewardBanner.tsx+++ b/src/routes/(main)/community/(list)/(home)/features/CreatorRewardBanner.tsx@@ -57,7 +57,7 @@ const styles = createStaticStyles(({ css }) => ({width: 50%;border-radius: 0 12px 12px 0;- background: url('/images/banner_creator.png') right center / auto 100% no-repeat;+ background: url('/app-images/banner_creator.png') right center / auto 100% no-repeat;${responsive.sm} {display: none;diff --git a/src/routes/(main)/community/(list)/_layout/Footer.tsx b/src/routes/(main)/community/(list)/_layout/Footer.tsxindex 4a4c40e9642..d03a6f2e47f 100644--- a/src/routes/(main)/community/(list)/_layout/Footer.tsx+++ b/src/routes/(main)/community/(list)/_layout/Footer.tsx@@ -18,11 +18,11 @@ const styles = createStaticStyles(({ css }) => ({background-size: 512px auto;`,footer_dark: css`- background-image: url('/images/community_footer_dark.webp');+ background-image: url('/app-images/community_footer_dark.webp');background-blend-mode: screen;`,footer_light: css`- background-image: url('/images/community_footer_light.webp');+ background-image: url('/app-images/community_footer_light.webp');background-blend-mode: multiply;`,}));