vercel / ai-chatbot

A full-featured, hackable Next.js AI chatbot built by Vercel
https://chat.vercel.ai
Other
6.25k stars 1.96k forks source link

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 2 months ago

bandinopla commented 2 months ago

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 commented 2 months ago

any update here ?

arfa123 commented 1 month ago

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

arfa123 commented 1 month ago

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", ], }, }