Closed teinett closed 11 months ago
Thanks for the detailed report. I would be surprised if the issue turns out to be caused by Astro. The fetch
function is now built-in to Node, which seems to be unable to connect to your strapi server. Are either of the two servers running with a container?
Are either of the two servers running with a container?
No, I don't use containers for this project.
Can you check if this command works?
node --eval "fetch('http://localhost:1337/api/posts')"
Result of node --eval "fetch('http://localhost:1337/api/posts')"
➜ landing-template git:(master) ✗ node --eval "fetch('http://localhost:1337/api/posts')"
node:internal/deps/undici/undici:11576
Error.captureStackTrace(err, this);
^
TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11576:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
cause: Error: connect ECONNREFUSED ::1:1337
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
errno: -61,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 1337
}
}
Node.js v18.18.1
➜ landing-template git:(master) ✗
use "http://127.0.0.1:1337/api/posts" instead of "http://localhost:1337/api/posts"
use "http://127.0.0.1:1337/api/posts" instead of "http://localhost:1337/api/posts"
Yes, it works now! Thanks a lot!
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
I created almost empty project - it's template for my other projects.
I installed StrapiJS admin and requested its API:
http://localhost:1337/api/posts
EXPECTED:
GOT THE ERROR:
Code of page
src/pages/index.astro
I tried:
const link = "https://catfact.ninja/breeds";
- RESULT is okeyconst link = "http://localhost:1337/api/posts";
- ERRORI tried to use this answer in AstroJS:
src/pages/index.astro
with fetch request and got error:Screenshots of correct answer of API are attached:
Postman
Firefox
What's the expected result?
I extected to receive the json list of posts, as it is in browser and Postman.
Link to Minimal Reproducible Example
no, as it request only published URL, not local one
Participation