Astro and Strapi configuration

chsanchHOBBY

2 months ago

Hi,

I have a project with 2 services: cms -> Strapi, web -> an Astro website and a Postgres DB. I'm using Railpack for both services.

I have managed to deploy the Strapi service, and is accesible through the public URL so I can add new data, is working properly, I can also access the API from my local development environment and get the data without any issue.

I have deployed the Astro website (I have follow the documentation https://docs.railway.com/guides/astro), but it is not able to get data from the Strapi service using the private network, I have configured the host in both services to 0.0.0.0 as mentioned in the documentation, and I'm using this to set the STRAPI_URL variable for the Astro website: =http://${{cms.RAILWAY_PRIVATE_DOMAIN}}:${{cms.PORT}} but this not working, instead if I set the variable to: https://${{cms.RAILWAY_PUBLIC_DOMAIN}} it works as expected, the Astro website is able to fetch data from the CMS.

The deploy logs show that the Astro website starts properly:

 [@astrojs/node] Server listening on 
  local: http://localhost:8080 	
  network: http://xx.xxx.xx.xx:8080

But when accessing the public URL I get a 500 error and in the logs I get this:

[ERROR] TypeError: fetch failed

    at node:internal/deps/undici/undici:13502:13

    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

    at async fetchApi (file:///web/dist/server/chunks/strapi_C6s-N_Ns.mjs:42:15)

    at async file:///web/dist/server/pages/index.astro.mjs:55:20

    at async callComponentAsTemplateResultOrResponse (file:///web/dist/server/chunks/astro/server_BKuxRg6R.mjs:1642:25)

    at async renderToAsyncIterable (file:///web/dist/server/chunks/astro/server_BKuxRg6R.mjs:1684:26)

    at async renderPage (file:///web/dist/server/chunks/astro/server_BKuxRg6R.mjs:2750:24)

    at async lastNext (file:///web/dist/server/chunks/_@astrojs-ssr-adapter_Bt_jtLbb.mjs:3019:25)

    at async callMiddleware (file:///web/dist/server/chunks/_@astrojs-ssr-adapter_Bt_jtLbb.mjs:1066:10)

    at async RenderContext.render (file:///web/dist/server/chunks/_@astrojs-ssr-adapter_Bt_jtLbb.mjs:3053:22)

am I missing something here to be able to connect both services using the private network?

Solved

7 Replies

2 months ago

You'll need to listen on :: for private network because it works over IPv6 (0.0.0.0 is IPv4-only)


Status changed to Awaiting User Response railway[bot] 2 months ago


chsanchHOBBY

2 months ago

If I set the HOST variable to :: the build fails, but it seems is a known issue with Strapi v5 https://github.com/strapi/strapi/issues/12285, just need to wait if they fix this soon


Status changed to Awaiting Railway Response railway[bot] 2 months ago


chsanchHOBBY

2 months ago

I have created a PR as an attempt to fix this issue: https://github.com/strapi/strapi/pull/23212


parmstarEMPLOYEE

2 months ago

I think we are stuck until Strapi makes a change


Status changed to Awaiting User Response railway[bot] 2 months ago


2 months ago

Hello,

With the right config there is no issue listening on :: -

https://github.com/railwayapp-templates/strapi/blob/main/config/server.js

The recommended Strapi template builds and runs just fine with HOST=::

Best,
Brody


chsanchHOBBY

2 months ago

I have modified my config/server.ts file to match the one provided in https://github.com/railwayapp-templates/strapi/blob/main/config/server.js, and now setting HOST to :: seems to work.

For the URL variable I'm using RAILWAY_PUBLIC_DOMAIN, because I understand that Strapi uses it for some features.

In the Astro app, I have to add a variable for the Strapi RAILWAY_PUBLIC_DOMAIN to be able to download images from the client side.

It seems there is no need to wait for the PR I have created in the Strapi repo.

Thanks!


Status changed to Awaiting Railway Response railway[bot] 2 months ago


chandrikaEMPLOYEE

2 months ago

Awesome, glad this worked out! ..and thank you for updating what worked here for future readers


Status changed to Awaiting User Response railway[bot] 2 months ago


Status changed to Solved chandrika 2 months ago