xod icon indicating copy to clipboard operation
xod copied to clipboard

As a XOD-dev I want to configure API request routing to production/staging/localhost with sane defaults

Open nkrkv opened this issue 6 years ago • 0 comments

XOD IDE has two target platforms:

  • Electron (has access to env vars)
  • Browser (has no access, the vars should be baked while building)

There are three development clusters:

  • Localhost
  • Staging
  • Production

There are several services to which IDE makes requests:

  • PM
  • Compiler
  • etc

All combinations of which platform on which cluster route to which service should be configurable in a flexible way.

The configuration tool should be two environment variables:

  • XOD_HOSTNAME
  • XOD_INSECURE_HTTP

The former is already used but the current implementation is incomplete and IDE on the staging cluster makes requests to the production API because the IDE image is shared and thus can’t be parametrized on k8s level (which is a good thing).

We can apply some clever deducing of the final endpoint URLs so that every desired combination is possible and if everything is built/run without overrides sane defaults are used.

How the environment values should be applied is better illustrated with a table:

Platform Cluster XOD_HOSTNAME XOD_INSECURE_HTTP Endpoint
Electron N/A blank blank https://api.xod.io/foo/bar
Electron N/A xod.show blank https://api.xod.show/foo/bar
Electron N/A xod.loc 1 http://api.xod.loc/foo/bar
Browser localhost blank blank https://api.xod.io/foo/bar
Browser localhost xod.loc 1 http://api.xod.loc/foo/bar
Browser xod.show blank blank https://api.xod.show/foo/bar
Browser xod.io blank blank https://api.xod.io/foo/bar

To acheive it the Browser version should perform some auto-detection:

  • If the XOD_HOSTNAME was specified at the build moment, honor it
  • If it was absent, deduce the URL base at runtime by looking at window.location

Acceptance criteria

  • [ ] The resolution works as described in the table
  • [ ] Electron’s environment variables are looked up at runtime, not at the build time; in other words, I can redirect requests between xod.loc, xod.show, and xod.io by exporting env vars and restarting IDE without rebuilding

nkrkv avatar Feb 01 '19 13:02 nkrkv