Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,15 @@ I'm the developer behind Developers Digest. If you find my work helpful or enjoy
- **Website**: Check out my website at [developersdigest.tech](https://developersdigest.tech)
- **Github**: Follow me on GitHub at [github.com/developersdigest](https://github.com/developersdigest)
- **Twitter**: Follow me on Twitter at [twitter.com/dev__digest](https://twitter.com/dev__digest)

## Troubleshooting

### GitHub Codespaces: "x-forwarded-host" does not match "origin"

If you run this in GitHub Codespaces you may see:

- `x-forwarded-host header ... does not match origin header ...`
- `Error: Invalid Server Actions request.`

This is caused by Next.js Server Actions CSRF protection when the app is behind a proxy.
This repo includes a `next.config.mjs` that allows Codespaces forwarded hosts.
26 changes: 26 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
// Fix for GitHub Codespaces (and other proxy setups) where Server Actions
// requests may arrive with forwarded hosts that don't match the `origin`
// header. Next.js blocks these by default for CSRF protection.
//
// Next.js 14.1.x expects this under `experimental.serverActions`.
// See: https://nextjs.org/docs/app/api-reference/config/next-config-js/serverActions#allowedorigins
experimental: {
serverActions: {
allowedOrigins: [
// local dev
'localhost',
'127.0.0.1',

// GitHub Codespaces
'*.app.github.dev',

// Vercel preview/prod (VERCEL_URL is e.g. "my-app.vercel.app")
...(process.env.VERCEL_URL ? [process.env.VERCEL_URL] : []),
],
},
},
};

export default nextConfig;