I am using Nuxt. For a new feature I need to start using Netlify functions. In order to run everything locally I started using the Netlify CLI.
With running the “netlify dev” command the CLI understands that I am using Nuxt and starts a server on http://localhost:8888/ and the nuxt default client on http://localhost:3000/
Starting Netlify Dev with Nuxt 2
> project@1.0.0 dev
> nuxt
ℹ Parsed 7 files in 1,2 seconds
ℹ Listening on: http://localhost:3000/
ℹ Preparing project for development
ℹ Initial build may take a while
ℹ Discovered Components: .nuxt/components/readme.md
✔ Builder initialized
✔ Nuxt files generated
WARN Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db
Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
ℹ Compiling Client
ℹ Compiling Server
✔ Server: Compiled successfully in 1.08m
✔ Client: Compiled successfully in 1.11m
ℹ Waiting for file changes
ℹ Memory usage: 835 MB (RSS: 993 MB)
ℹ Listening on: http://localhost:3000/
✔ Waiting for framework port 3000. This can be configured using the 'targetPort' property in the netlify.toml
┌─────────────────────────────────────────────────┐
│ │
│ ◈ Server now ready on http://localhost:8888 │
│ │
└─────────────────────────────────────────────────┘
Since I have a comprehension issue here: Why does it split up in client and server in the first place? Isn’t it possible to run everything on a single port?
Now the actual issue:
With having a client and server calling my endpoint:
const res = await fetch('/.netlify/functions/reviews');
results in the error:
Error in fetch(): TypeError: Only absolute URLs are supported
As far as I have understood from looking up this issue, this error results because of the two different environments the project is running on:
With
const res = await fetch('http://localhost:8888/.netlify/functions/reviews');
I am getting a correct response.
Do I really need to identify dev and prod environment here or is there another solution to this issue?