Peanuts
next.js 解决 `x-forwarded-host` header does not match `origin` header with value from a forwarded Server Actions request
178 字
1 分钟
next.js 解决 `x-forwarded-host` header does not match `origin` header with value from a forwarded Server Actions request
在 GitHub codespaces 上开发 next.js 项目,端口穿透出来后访问,结果报错:
`x-forwarded-host` header does not match `origin` header with value from a forwarded Server Actions request.解决方案:
- 如果需要,首先更新 next.js 。参见 https://nextjs.org/docs/messages/version-staleness ,运行命令:
pnpm add next@latest这应当是不会报错了。但如果您像笔者一样使用了 ppr: true ,就应当使用 canary 版本,不然后续可能会出错。
- 修改
next.config.js,添加experimental.serverActions.allowedOrigins。
例如我这里:
import type { NextConfig } from 'next';
const nextConfig: NextConfig = { /* config options here */ experimental: { serverActions: { allowedOrigins: [ 'localhost:3000', // localhost 'super-duper-space-*****-*****-3000.app.github.dev', // Codespaces ], }, ppr: true, }, images: { remotePatterns: [ { hostname: 'avatar.vercel.sh', }, ], },};
export default nextConfig;然后重新启动后就能成功访问了。
支持与分享
如果这篇文章对你有帮助,欢迎分享给更多人或投喂支持!
next.js 解决 `x-forwarded-host` header does not match `origin` header with value from a forwarded Server Actions request
https://www.infvar.com/posts/xforwardedhost/ 相关文章 智能推荐
1
How to Create a React MUI Project from Scratch
实验室 2024-04-03
2
解决macOS报错 yld[1515]: Symbol not found
实验室 2025-01-28
3
迁站记:自旧域至新域,自 Jekyll 至 Astro
展览厅 记一次博客由旧域迁移至新域,并由 Jekyll 更易为 Astro 之经过与所感。
4
用 J1900 小主机打造一台 All-in-One 校园网软路由:从零开始的完整记录
实验室 一台没有显示器的 J1900 小主机、一块 128G SSD、一张 Intel 6205 无线网卡,如何在宿舍环境里变身成集 AP、软路由、私有存储于一体的网络中枢。
5
「无尽计划」半公益产品矩阵
实验室 因为手上有一些闲置的服务器资源,不如将它们变成一些有价值的服务,为开发者、创作者和普通用户提供稳定、免费的基础设施。🤗
随机文章 随机推荐
无穷量?