Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CODESPACE ERROR: x-forwarded-host header with value xxx-3000.app.github.dev does not match origin header with value localhost:3000 from a forwarded Server Actions request. Aborting the action. #384

Open
bandinopla opened this issue Jul 15, 2024 · 3 comments

Comments

@bandinopla
Copy link

Running this from a fork on github codespaces throws that error when sending a chat message...
I added this to see if it made it work, but it doesn't.
Any idea?

//layout.tsx
export const metadata = {
  metadataBase: process.env.VERCEL_URL
  ? new URL(`https://${process.env.VERCEL_URL}`)
  : process.env.CODESPACES
             ? new URL(`https://${process.env.CODESPACE_NAME}-3000.github.dev`) // Construct the Codespace-specific URL
             : new URL('http://localhost:3000'),
}
//next.config.js
/** @type {import('next').NextConfig} */
module.exports = { 
  async headers() {
    return [
      {
        source: '/(.*)',
        headers: process.env.CODESPACES
          ? [
              {
                key: 'X-Forwarded-Host',
                value: `${process.env.CODESPACE_NAME}-3000.github.dev`,
              },
              {
                key: 'Access-Control-Allow-Origin',
                value: `https://${process.env.CODESPACE_NAME}-3000.github.dev`,
              },
            ]
          : [],
      },
    ]
  }, 
}
@bajoski34
Copy link

any update here ?

@arfa123
Copy link

arfa123 commented Aug 13, 2024

also facing same problem, I am also using Github Codespace and unable to test server actions, please guide us

@arfa123
Copy link

arfa123 commented Aug 13, 2024

Running this from a fork on github codespaces throws that error when sending a chat message... I added this to see if it made it work, but it doesn't. Any idea?

//layout.tsx
export const metadata = {
  metadataBase: process.env.VERCEL_URL
  ? new URL(`https://${process.env.VERCEL_URL}`)
  : process.env.CODESPACES
             ? new URL(`https://${process.env.CODESPACE_NAME}-3000.github.dev`) // Construct the Codespace-specific URL
             : new URL('http://localhost:3000'),
}
//next.config.js
/** @type {import('next').NextConfig} */
module.exports = { 
  async headers() {
    return [
      {
        source: '/(.*)',
        headers: process.env.CODESPACES
          ? [
              {
                key: 'X-Forwarded-Host',
                value: `${process.env.CODESPACE_NAME}-3000.github.dev`,
              },
              {
                key: 'Access-Control-Allow-Origin',
                value: `https://${process.env.CODESPACE_NAME}-3000.github.dev`,
              },
            ]
          : [],
      },
    ]
  }, 
}

add "localhost:3000" in 'allowedOrigins' resolves your issue
experimental: { serverActions: { allowedOrigins: [ "localhost:3000", "xxx-3000.app.github.dev", ], }, }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants