a year ago
Hello everyone,
I've been trying desperately since yesterday to deploy a strapi that doesn't come from the official Railway template and to be able to communicate from a Next.js project (with the fetch function) also deployed on Railway on the private network.
I made the necessary changes in config/server.ts to replicate the same thing as in the template:
export default ({ env }) => ({
host: env("HOST", "0.0.0.0"),
port: env.int("PORT", 1337),
app: {
keys: env.array("APP_KEYS"),
},
webhooks: {
populateRelations: env.bool("WEBHOOKS_POPULATE_RELATIONS", false),
},
url: env("URL"),
proxy: true,
});In Strapi's env variables, I set this on Railway :
HOST with ::
URL with http://${{RAILWAY_PRIVATE_DOMAIN}}
The service starts up with the following log:
Welcome back!
To manage your project š, go to the administration panel at:
http://strapi-portfolio.railway.internal/admin
To access the server ā”ļø, go to:
http://strapi-portfolio.railway.internalHowever Next.js at build time is unable to fetch Strapi via the RAILWAY_PRIVATE_DOMAIN⦠here's the error I get :
[cause]: Error: getaddrinfo ENOTFOUND strapi-portfolio.railway.internal
However, I've configured STRAPI_BASE_URL in my Next.js project for :
http://strapi-portfolio.railway.internal/api
Would it be totally impossible to communicate via Railway's private network with Strapi, or am I missing something?
Thank you in advance.
ā Deployment information is only viewable by project members and Railway employees.
12 Replies
a year ago
Oh dear, so I have to make my Strapi address public?
Isn't there an alternative to use only the private network with Next.js in the build?
a year ago
Using the New Builder solved the problem.
Don't forget to add :: to HOST and remove URL env variable if you plan to use only private networking.
a year ago
Please know that we can not currently provide support when using the new builder, it's in an unmaintained Beta state right now.
We strongly recommend you not to use it, simply do not call a private domain during build, do it during runtime.
a year ago
Thanks for your reply. But with NextJS we need to fetch at build time for static generation.
We donāt want to made our api public, how could we fix this without the new builder ? Do you have a workaround ?
The new builder is in beta, but do you think it will be out of beta soon?
a year ago
I've configured my Strapi to be publicly accessible only via Cloudflare Tunnels (Zero-Trust) to get around this New Builder problem.
I created a Service Token on Cloudflare Tunnels that I add to my Next.js fetch function to allow only calls from my Next.js application to Strapi and nothing else. I'm always in favor of privatizing an application and making it accessible only on a private network when there's no need for public use.
I think I've found a way to change environment variables dynamically at buildtime and runtime on Next.js.
For example, with the env variable NEXT_PHASE, which is given to me natively by Next.js, the env lets me know which phase I'm in (buildtime or runtime), here's an example:
import {
PHASE_PRODUCTION_BUILD,
} from ānext/constantsā;
console.log(
"Building Next app now ?",
process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD,
);Depending on the NEXT_PHASE, I can then switch between the Public Strapi URL via Cloudflare Tunnel at buildtime, and the Private Strapi URL at runtime to avoid Network Egress fees with Railway.
Perhaps it would be interesting to document this usecase in the official Railway doc, as I think quite a few of us have this use case with Next.js building scenario ?
a year ago
Personally I think this solution is far more complex than it needs to be, simply don't call strapi at build time, call it during runtime before starting the app.
a year ago
Personally I think this solution is far more complex than it needs to be, simply don't call strapi at build time, call it during runtime before starting the app.
Yes, but I need to generate static pages at build time... so Next.js call strapi at build because my app pages have strapi calls 
I can't remove the main feature of Next.js for just Railway š„¹
a year ago
a year ago
did you have a tutorial for that ?