RutgersGRID / hubs

Duck-themed multi-user virtual spaces in WebVR. Built with A-Frame.
https://hubs.mozilla.com
Mozilla Public License 2.0
0 stars 0 forks source link

How Hubs Admin Accesses the Database #53

Open Voxelghiest opened 1 year ago

Voxelghiest commented 1 year ago

This ticket documents the ways in which Hubs Admin communicates with the PostgREST server in order to access data.

Voxelghiest commented 1 year ago

How Hubs Admin Accesses the Database

Hubs Admin can access the PSQL database in two ways: either directly through PostgREST, or by proxying those PostgREST requests through Reticulum, which then handles accessing the database itself (see admin.js).

Which method it uses depends on the environment variable POSTGREST_SERVER. If POSTGREST_SERVER is set (i.e., is not null or empty), then it uses PostgREST; if not, it proxies through Reticulum.

So far, we have been running Hubs Admin under the local configuration profile (by running npm start local to start the app). By default, the local configuration is set up to proxy through Reticulum (see webpack.config.js).

Voxelghiest commented 1 year ago

I was asked by @yalegria to investigate the URL requests that Hubs Admin makes to Reticulum in order to access the database. I found that Hubs Admin makes a GET request to https://hubs.local/api/postgrest when accessing sections of the database. For example, when accessing the "Avatars" tab in the Hubs Admin webpage, the following request is registered by Reticulum (in the interactive IEx console):

Image

I was able to use curl to ping this URL, but the request was denied for authentication reasons, which makes sense:

Image

Voxelghiest commented 1 year ago

I've found further information on the URLs being used to fetch data from Reticulum.

When Reticulum receives a fetch request, it determines which module should handle the specific call depending on the requested URL. That routing is defined in router.ex. For example, in the above comment, when Reticulum gets a request for /api/postgrest/avatars, it recognizes the "postgrest" prefix and routes it through the RetWeb.PostgrestProxy module, which handles getting the info from the PostgREST server and returning it.