Cannot access nextjs dev server on local network
Unanswered
glaucusec posted this in #help-forum
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).
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).
5 Replies
Yacare Caiman
try to allow ports 4000 to by firewalls
@Yacare Caiman try to allow ports 4000 to by firewalls
Brown bear
Port firewall would not cause a CORS error.
I'm unable to recreate this issue on my local machine. @glaucusec 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: '*'
}
] : []
}
]
}
Yacare Caiman
is your 192.168.135.191:4000 and localhost:3000 running on same machine?