Skip to content

feat: add baseURL option for dynamic http question - #1541

Merged
zacharyjhankin merged 40 commits into
developfrom
feat-dynamic-http-option3
Jul 6, 2026
Merged

feat: add baseURL option for dynamic http question#1541
zacharyjhankin merged 40 commits into
developfrom
feat-dynamic-http-option3

Conversation

@zacharyjhankin

@zacharyjhankin zacharyjhankin commented May 27, 2026

Copy link
Copy Markdown
Collaborator

Description

This adds an option to dynamically set the baseURL of the dynamic question to the domain that is currently deployed. NOTE: needs http:// in the beginning of your BASE_URL environment variable. (this PR updates example.env and docker-compose.yml)

Motivation and Context

We are using a graphQL endpoint to obtain the list of countries that the users can select as their country. This will always use the domain that the UOC is deployed on, and different environments will have different domains. This lets the code dynamically call its own domain. We also don't want users getting confused.

How Has This Been Tested

I made a dynamic http question in the develop branch and checked that in the proposal it would work to make the countries. using:

http://localhost:3000/graphql?query=query%20ExampleQuery%20%7B%20countries%20%7B%20value%20%7D%20%7D

$.data.countries[*].value

content-type:application/json

then I switched to my branch and ran npm run generate:sdk

I confirmed my conversion worked to add baseURL to the dynamic question.

I confirmed that the existing question would still work without changing anything in a new proposal

I then edited my proposal template HTTP question to use my baseURL setting.

I confirmed that the country list would still be shown in the proposal.

image image image image

NOTE:

There is an existing bug that means the URL that the proposal uses when someone is filling it out to get the countries is the parent question. Not the question that is edited for the specific template. This means you may encounter this error when testing. So make sure to edit both the parent question and the template question when testing this to see it actually being used.

Tests included/Docs Updated?

Added backend unit test

  • I have added tests to cover my changes.
  • All relevant doc has been updated

@zacharyjhankin zacharyjhankin changed the title add: baseURL option for dynamic http question feat: baseURL option for dynamic http question May 27, 2026
@zacharyjhankin zacharyjhankin changed the title feat: baseURL option for dynamic http question feat: add baseURL option for dynamic http question Jun 5, 2026
@zacharyjhankin
zacharyjhankin marked this pull request as ready for review June 29, 2026 12:58
@zacharyjhankin
zacharyjhankin requested a review from a team as a code owner June 29, 2026 12:58
@zacharyjhankin
zacharyjhankin requested review from ellen-wright and removed request for a team June 29, 2026 12:58
@zacharyjhankin

Copy link
Copy Markdown
Collaborator Author

Updated to work with http:// in the base_url environment variable. Will not work if your BASE_URL is just localhost:3000


function constructDynamicURL(url: string, useBaseURL: boolean): string {
if (useBaseURL) {
return `http://${process.env.BASE_URL}/${url}`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how much work we should do here to deal with how the base url is set? It's a bit like when we were setting the UAS_INSTANCE environment variable - trailing slash, already includes http or https?

In most application, a double forward slash would usually not break anything (so mydomain.com//my-endpoint would still go to mydomain.com/my-endpoint), so that's not much of an issue, so it might just be that we don't include the http bit.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comment, that is a very good spot. The standard way for what is meant by "base_url" would include the HTTP, but in the existing .env file there is not http. I updated my code to depend on http being include in the BASE_URL and changed the example .env. I left a comment in the general chat so people know of this change. @ellen-wright is aware too.

The code now reads

${process.env.BASE_URL}/${url};

So neither the baseURL of the URL path should contain a trailing or leading slash. I have that in my regex to show users and make it obvious.

@zacharyjhankin
zacharyjhankin enabled auto-merge (squash) July 6, 2026 09:24
@zacharyjhankin
zacharyjhankin disabled auto-merge July 6, 2026 09:25
@zacharyjhankin
zacharyjhankin enabled auto-merge (squash) July 6, 2026 09:25
@zacharyjhankin
zacharyjhankin merged commit e56210d into develop Jul 6, 2026
42 of 51 checks passed
@zacharyjhankin
zacharyjhankin deleted the feat-dynamic-http-option3 branch July 6, 2026 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants