Web routes from Api side and vice versa

Hi Redwood people! :wave:

I am wondering what does Redwood provide to handle URLs/routes on the API side, and how both sides can actually safely reference each other’s routes.

My situation:

  • one custom serverless function that is a redirect target in a flow with a 3rd party
  • on the web side, a component that initiates that flow to the 3rd party

To initiate the flow, a URL with a redirect_uri query string parameter must be generated.
To make things clean, I would like to avoid hard-coding the function URL in my component.

:point_right: Is there a way for my web side to do this? Something like api.routes.myFunctionName()?

AFAIK, there isn’t even a way to do that within the API side itself?

Secondly, in that function I will handle the return code for that 3rd party flow, and depending on the result I want to redirect users to a different page on my web side.
Once again, I’d rather not hard-code those redirect URLs in my function code.

:point_right: Is there a way for my function to reference the web side routes?

Thanks!

Hello @olance,

There currently isn’t a way to do exactly what you’re looking for. The Api and web sides are fairly isolated, and is something we will only look to address in v2.

Here’s a couple of other ways though:

  1. Use an env var to set your AUTH_REDIRECT_URL so you don’t need to hardcode
  2. You can use a combination of global.RWJS_API_URL + process.env.AUTH_REDIRECT_URL (see Docs - Environment Variables : RedwoodJS Docs)

HTH!

Danny

Hey @danny thanks for the reply :slight_smile:

Glad to know it’s on your radar!
The env variables will do indeed until then, and thanks for the pointer on RWJS_API_URL I had forgotten about it :slight_smile: