Different URL for Modern UI and API endpoint

Victor Butler2 years ago

Hi,

Is it possible to have two different URLs for the modern UI and the API endpoint? For example:

Modern UI -> https://subdomain.example.com

API endpoint: -> http://example.com:8082

I am using proxy pass as outlined here.

Anton Tananaev2 years ago

Why do you need to have them on different URLs?

Victor Butler2 years ago

Additional security mostly - I'd like to restrict access to the API and/or modern UI for user-agents, referrers, countries or IPs that match certain criteria.

Anton Tananaev2 years ago

You should be able to do all that by path. Completely different URLs shouldn't be required.

Victor Butler2 years ago

Path might be possible as well but needs additional coding and testing, something that was already done for different URLs.

So, what would you advice, is it possible to have two different URLs for the API and the modern UI?

Anton Tananaev2 years ago

Probably possible, but there are many issues with it. For example, sessions authentication might not work without some changes/configuration. Also, you would need to change the code to point to the different endpoint. Basically it won't work out of the box.

Victor Butler2 years ago

When you say that I would need to change the code, are you referring to the traccar server or modern UI?

That is, if we are to change the modern UI URL, should we do this from the server source code or the traccar-web? Any idea which files to look at?

Anton Tananaev2 years ago

Web app code.

Victor Butler2 years ago

I assume it's not the .env file: REACT_APP_URL_NAME='localhost:8082'?

That just tells the UI that the server is located at localhost. Which file should I look at if I want to edit the URL?

As far as I can see it's the PUBLIC_URL that I need to edit but I can't fine where it is defined.

Juliano2 years ago

You can usually do what you want by changing the .env file. Then just compile it will work 100%.

REACT_APP_TRACCAR_URL='http://YOUR_IP:8082'
REACT_APP_URL_NAME='YOUR_IP:8082'
Victor Butler2 years ago

Hey Juliano,

Thank you for jumping in!

I can't find a reference in the source code for REACT_APP_TRACCAR_URL. Shouldn't it be declared somewhere else?

Juliano2 years ago

It is in the .env file which in many pcs is hidden. remembering that the file only exists in the source code, in the compiled modern folder it does not exist.

Victor Butler2 years ago

Yes, I know what the .env file is. In the original .env file for version 5.6, there is no REACT_APP_TRACCAR_URL. This is what there is:

ESLINT_NO_DEV_ERRORS=false
REACT_APP_URL_NAME='localhost:8082'
REACT_APP_VERSION=$npm_package_version

Question is, how do we give an URL for the modern UI that is different form the API endpoint URL. (given the issues mentioned by Anton are fixable in the source code).