Help with connecting frontend service to backend service using private networking
rayzhudev
TRIALOP

a year ago

My frontend can't connect to my backend when I use the internal url. I'm using bun to host my server and when going to the backend's public domain it works. I've attempted connecting with a variety of options, with/without https, with/without port.

Solved

45 Replies

rayzhudev
TRIALOP

a year ago

10248319-2e2b-4990-bb6b-2ee0708634b4


dev
MODERATOR

a year ago

With 'frontend' do you mean your frontend code?


rayzhudev
TRIALOP

a year ago

yes


rayzhudev
TRIALOP

a year ago

so this is the api url my frontend is using https://prophesy-backend.railway.internal


maddsua
HOBBY

a year ago

Well, international urls are pointing to internal domain names that are resolved by the container runtime


maddsua
HOBBY

a year ago

Those aren't publicly accessible


rayzhudev
TRIALOP

a year ago

1322038147579777000


maddsua
HOBBY

a year ago

I assume you're trying to connect to that from a browser


rayzhudev
TRIALOP

a year ago

I'm hosting my frontend here: https://prophesy-web-production.up.railway.app/
and I want to connect to the backend service


rayzhudev
TRIALOP

a year ago

so yes, from a browser


maddsua
HOBBY

a year ago

Nope that wouldn't work


rayzhudev
TRIALOP

a year ago

can you tell me what I should be doing instead?


rayzhudev
TRIALOP

a year ago

I know it doesn't work


maddsua
HOBBY

a year ago

Only the SSR part of next wound be able to use internal urls


maddsua
HOBBY

a year ago

Umm like, use a public url?


maddsua
HOBBY

a year ago

Idk what your requirements tho


rayzhudev
TRIALOP

a year ago

is there a way to do it without publicly exposing the backend?


maddsua
HOBBY

a year ago

Just to reiterate, what you are saying is that you want your backend to be publicly accessible without being exposed to public


rayzhudev
TRIALOP

a year ago

no, I want my backend to only be accessible by my frontend


rayzhudev
TRIALOP

a year ago

so you can only make api requests through my website


maddsua
HOBBY

a year ago

Then, cors is the answer


maddsua
HOBBY

a year ago

U gotta property configure it and then you'll be only able to access ur BE from ur FE domain


rayzhudev
TRIALOP

a year ago

ok, do you have any docs on how I can do that?


rayzhudev
TRIALOP

a year ago

I'm not familiar with railway



maddsua
HOBBY

a year ago

CORS is not specific to railway at all


maddsua
HOBBY

a year ago

But tldr is that you CAN NOT truly prevent anyone online from marking requests to a service that is publicly exposed on the internet


rayzhudev
TRIALOP

a year ago

so what url would I reference with cors? and how do I set up my backend service on railway with that


maddsua
HOBBY

a year ago

Because if a legit front end domain can access a service, than can anyone else


maddsua
HOBBY

a year ago

Unless you use authorization


rayzhudev
TRIALOP

a year ago

I thought railway has a feature where the services within a project can access each other, but outside things can't


rayzhudev
TRIALOP

a year ago

like a local network thing


maddsua
HOBBY

a year ago

Yes railway has it


maddsua
HOBBY

a year ago

However


maddsua
HOBBY

a year ago

A client's browser is not a service


rayzhudev
TRIALOP

a year ago

right


maddsua
HOBBY

a year ago

So it cannot possibly be scoped to a private network


rayzhudev
TRIALOP

a year ago

so do I keep the public domain with my backend service, and use cors to block requests from other domains?


maddsua
HOBBY

a year ago

Private networks make sense when you have services that aren't exposed to public in any way, like a database to backend connection


maddsua
HOBBY

a year ago

But backend to frontend only works for the SSR part, not to the browser


maddsua
HOBBY

a year ago

That's pretty much how it's done everywhere


maddsua
HOBBY

a year ago

You would need to explicitly allow the legit domains and reject requests from any others


rayzhudev
TRIALOP

a year ago

yep ok thanks


maddsua
HOBBY

a year ago

Again, not railway specific at all, just general web shenanigans


dev
MODERATOR

a year ago

!s


Status changed to Solved dev about 1 year ago


Loading...