import { FaapiPlugin } from '@faapi/faapi'; /** 插件选项(来自 faapi.config.ts plugins 声明的第二个元素或 options 字段) */ interface NextPluginOptions { /** 开发模式,默认 NODE_ENV !== 'production' */ dev?: boolean; /** Next.js 项目目录,默认 '.' */ dir?: string; /** faapi API 路径前缀,默认 '/api';匹配此前缀的请求走 faapi,其余走 Next.js */ apiPrefix?: string; /** * 是否自动开启 Next.js 的 experimental.trustHostHeader,默认 true * * 反向代理(Nginx/Caddy 等)场景下,Next.js 默认用固定的 hostname:port 构造 * initURL(如 https://localhost:3000/path),忽略代理透传的 Host 头,导致 * SSR 重定向/链接指向错误域名。开启 trustHostHeader 后,Next.js 直接用 * req.headers.host 构造 URL,正确反映客户端原始请求。 * * 实现方式:插件用 Next.js 的 loadConfig 加载用户 next.config.ts,合并 * experimental.trustHostHeader=true,再通过 next() 的 conf 选项传入。 * 用户在 next.config.ts 中的其他配置会被保留。若加载失败则退回不传 conf, * 此时需手动在 next.config.ts 中配置。 * * 设为 false 可禁用此行为(如非反向代理场景,或用户想手动控制)。 */ trustHostHeader?: boolean; } /** * Next.js + faapi 集成插件 * * 通过 faapi.config.ts 的 plugins 字段加载: * * ```ts * export default { * plugins: [ * ['@faapi/next', { dir: '.' }] // 带选项的元组 * ], * } satisfies FaapiConfig; * ``` * * 启动时用 `faapi` 命令,自动集成 Next.js,无需写 custom server 代码。 */ declare const nextPlugin: FaapiPlugin; export { type NextPluginOptions, nextPlugin as default };