Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/base url config #836

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

liuyuanzhi-cn
Copy link

Problem

I would love to use the second-level domain name of nginx to deploy Answer. However, this requires the webapp to work on relative url path (e.g. /foo/questions) or support setting a base url via configuration.

Solution

Add support for setting a base/root url in the configuration or make the webapp work on relativ urls. Having this option is very useful in a variety of deployment scenarios (e.g. behind a reverse proxy).

Adds the config option REACT_APP_BASE_URL_PATH . When set to a value like /foo, Anwser will be served from hostname:port/foo.

Usage

  1. edit the ui/.env.production file
...
REACT_APP_BASE_URL_PATH=/foo
...
  1. Recompile
make ui
make build
  1. Initialization and Run
# Initialization
INSTALL_PORT=9080 REACT_APP_BASE_URL_PATH=/foo ./answer init -C ./answer-data/
# Run
REACT_APP_BASE_URL_PATH=/foo ./answer run -C ./answer-data/

Note:

  1. If the value of REACT_APP_BASE_URL_PATH is the default "", there is no need to set the environment variable.
  2. The value of REACT_APP_BASE_URL_PATH must not end with /. For example, PUBLIC_URL=/foo is correct, while PUBLIC_URL=/foo/ is incorrect.

@fenbox
Copy link
Member

fenbox commented Mar 12, 2024

Thank you @liuyuanzhi-cn, this PR seems to be related to #335

@fenbox fenbox requested a review from LinkinStars March 12, 2024 08:15
@shuashuai
Copy link
Member

react-router-dom supports adding basename, which will save a lot of files. by adjusting like this, there should be less code modifications.

 const router = createBrowserRouter(routes, {
    basename: process.env.REACT_APP_BASE_URL_PATH,
  });

However, by adding basename, no matter how you adjust it, there will be a certain degree of code intrusion, and a lot of testing is required, because it may also include some callback addresses returned by the API, or the oauth address in the plug-in, etc.

Another way is to directly use nginx as a proxy without changing the code in the business. How effective is this method?

@shuashuai
Copy link
Member

@liuyuanzhi-cn

I looked at the changes you submitted. There will be a lot of code intrusion and modification. I tried to achieve it by adding basename in combination with react-router-dom. This can be achieved with only a small amount of changes. You can refer to here.

Of course, I only modified the front-end related routing configuration, and some routes returned through the API have not yet been adjusted. This modification should be reasonable.

@liuyuanzhi-cn
Copy link
Author

@liuyuanzhi-cn

I looked at the changes you submitted. There will be a lot of code intrusion and modification. I tried to achieve it by adding basename in combination with react-router-dom. This can be achieved with only a small amount of changes. You can refer to here.

Of course, I only modified the front-end related routing configuration, and some routes returned through the API have not yet been adjusted. This modification should be reasonable.

Indeed, this looks great, it's much more elegant this way, with a lot less code changes.

@shuashuai
Copy link
Member

@liuyuanzhi-cn
I looked at the changes you submitted. There will be a lot of code intrusion and modification. I tried to achieve it by adding basename in combination with react-router-dom. This can be achieved with only a small amount of changes. You can refer to here.
Of course, I only modified the front-end related routing configuration, and some routes returned through the API have not yet been adjusted. This modification should be reasonable.

Indeed, this looks great, it's much more elegant this way, with a lot less code changes.

We will confirm support for this requirement in subsequent versions as soon as possible! Of course, if you are interested, you are welcome to continue to submit PR according to this idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants