2024-04-03 20:28:09 -04:00
# Path-based Routing
2024-06-28 15:03:25 +00:00
If you are using the frontend, the frontend and backend need to share cookies.
The backend, in particular, sets a cookie, and the frontend needs to read it.
As such, you cannot run the frontend and backend on different subdomains, like this:
2024-04-03 20:28:09 -04:00
2024-04-05 19:14:09 +00:00
- frontend.example.com
- backend.example.com
2024-04-03 20:28:09 -04:00
Instead, we often run them like this:
2024-06-28 15:03:25 +00:00
- example.com for the frontend
- api.example.com for the backend
2024-04-03 20:28:09 -04:00
2024-06-26 02:55:03 +00:00
This works since the backend can set a cookie for the entire domain, and the frontend can read it.
2024-04-03 20:28:09 -04:00
2024-06-26 02:55:03 +00:00
Another alternative that works well is to run them on the same host but with different paths, like this:
2024-04-03 20:28:09 -04:00
2024-06-28 15:03:25 +00:00
- spiff.example.com for the frontend
- spiff.example.com/api for the backend
2024-04-03 20:28:09 -04:00
2024-06-26 02:55:03 +00:00
To accomplish this path-based routing scenario, set environment variables like this in the frontend:
2024-04-03 20:28:09 -04:00
```sh
SPIFFWORKFLOW_FRONTEND_RUNTIME_CONFIG_APP_ROUTING_STRATEGY=path_based
```
2024-06-26 02:55:03 +00:00
And in the backend, you may need to set:
2024-04-03 20:28:09 -04:00
```sh
SPIFFWORKFLOW_BACKEND_URL_FOR_FRONTEND=https://spiff.example.com
SPIFFWORKFLOW_BACKEND_URL=https://spiff.example.com/api
# if you happen to be using the internal openid server. do not do this in production.
SPIFFWORKFLOW_BACKEND_OPEN_ID_SERVER_URL=https://spiff.example.com/api/openid
# if you can manage, use in-cluster DNS for connector. you may need a different host or port.
SPIFFWORKFLOW_BACKEND_CONNECTOR_PROXY_URL=http://spiffworkflow-connector:8004
```
2024-04-03 20:30:27 -04:00
2024-06-26 02:55:03 +00:00
The backend does not support paths like `/api/v1.0/status` , but instead wants `/v1.0/status` .
As such, a proxy in the frontend or backend will need to remove the `/api` part of the path before handing the request to the backend.
2024-04-05 19:14:09 +00:00
2024-06-26 02:55:03 +00:00
If you are hitting the backend at a URL like spiff.example.com/api and not rewriting the path to remove the /api prefix, you can inform the backend about this situation by setting this environment variable:
2024-04-05 19:14:09 +00:00
```sh
SPIFFWORKFLOW_BACKEND_WSGI_PATH_PREFIX=/api
```
2024-06-26 02:55:03 +00:00
This will be used as the WSGI `SCRIPT_NAME` , which essentially removes the prefix before handing the URL to the app for routing, but also allows URLs generated by the app to return things like /api/v1.0/status.
WSGI is a standard for serving Python apps, and there are implementations like Gunicorn, Green Unicorn, uWSGI, mod_wsgi, CherryPy, etc.