#Cannot access nextjs dev server on local network

6 messages · Page 1 of 1 (latest)

glacial sandal
#

My dev server is running on localhost:4000. I can only access from the localhost:4000. whenever accessed via the device ip, all network requests fails.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://192.168.135.191:4000/src/main.tsx. (Reason: CORS request did not succeed). Status code: (null).

soft valleyBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

late jasper
#

try to allow ports 4000 to by firewalls

open cargo
#

I'm unable to recreate this issue on my local machine. @glacial sandal are you trying to access your next.js server from a different locally hosted server? For example, fetching https://192.168.135.191:4000/ from https://localhost:3000/ would fail, and you would need to allow localhost in your CORS headers (or, allow * when in development).

#

For example, in your payload config:

async headers() {
  return [
    {
      source: '/:path*',
      headers: process.env.NODE_ENV === 'development' ? [
        {
          key: "Access-Control-Allow-Origin", value: '*'
        },
        {
          key: "Access-Control-Allow-Methods", value: '*'
        },
        {
          key: "Access-Control-Allow-Headers", value: '*'
        }
      ] : []
    }
  ]
}