Static Site and Web Service Communication in Pull Requests

Hi,

We have a Web Service and Static Site deployed with Render, with each residing in the same git repository.

We have pull request previews enabled, and those are correctly deploying each service every time we create a new pull request.

Here’s the problem we’re hitting though: Our Static Site invokes the Web Service with an HTTP request, aka fetch("https://my-app.onrender.com"). But, for pull requests Render generates a dynamic URL, aka https://my-app-pr-12.onrender.com/, and because that URL is dynamic, we have no way of consistently referring to that URL.

We’re looking to set up a staging environment and finding that tricky to do with Render. Ideally we’d be able to designate a certain branch as a staging branch, have automated deployments from that branch, and have a consistent URL that we can use.

Is this sort of thing possible, and do you have any other tips to point us in the right direction?

Thanks,
TJ

Hello,

You can use Render Blueprints to manage relationships between multiple services. In this case, you would be able to set an environment variable in your static site with:

envVars: # this is in the static svc
key: BACKEND_SERVICE_HOST
fromService:
    name: my-app
    type: web
    envVarKey:RENDER_EXTERNAL_URL

Then reference that URL when making requests from your static site.

Also be sure to set previewsEnabled: true at the top level of your blueprint, rather than setting prPreviewsEnabled on each service.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.