Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

technologiestiftung/qtrees-supabase

Repository files navigation

All Contributors

QTrees Supabase

This is the Supabase.com setup for the QTrees project. It uses edge functions to pass requests through to another API created using Postgrest. Since this API is not public and there are no docs for it you won't be able to use the edge functions from this repo.

Prerequisites

  • supabase account
  • supabase cli
  • Secondary API and Database (out of scope for these docs)

Installation

git clone <repository>

Deployment

Before you can deploy the project to the Supabase.com, you need to:

  • Login using the supabase cli
  • Create a new project using the supabase dashboard
  • Enable postgis and moddatetime in the dashboard for your database
  • Obtain you project ref/id (find it in the URL)
  • Obtain your project database url (looks like this postgresql://postgres:[YOUR-PASSWORD]@db.[abcdefghijklmnopqrst].supabase.co:5432/postgres)
  • Create two copies of .env.defaults and name them .env and .env.local and fill in the blanks
cd <repository>
supabase link --project-ref <abcdefghijklmnopqrst>
supabase db remote set <remote database connection url>
supabase db push # [--dry-run]
supabase functions deploy ml-api-passthrough

Development

cd <repository>
supabase start
supabase functions serve ml-api-passthrough --env-file ./supabase/.env.local

Make requests to the passthrough API

The passthrough API is a simple proxy that passes requests to the secondary API. The secondary API is a Postgrest instance that is connected to the trees database. All Postgrest filters and queries are passed through to the secondary API. Even though you actually would make a GET request, it is a restriction of the Supabase edge functions that you can only make POST and OPTIONS requests.

Todo:

  • Fill in your anon token
  • Fill in your project ref

For the /trees route/table requests without gml_id searchParams are rejected.

curl -L -X POST 'https://[abcdefghijklmnopqrst].functions.supabase.co/ml-api-passthrough/trees?gml_id=eq.1' -H 'Authorization: Bearer [YOUR ANON KEY]'

Or with Javascript:

{
	async function main() {
		const gml_id = "[SOME GML ID]";
		const anon_token = "[YOUR ANON KEY]";

		const response = await fetch(
			`<https://[abcdefghijklmnopqrst].functions.supabase.co/ml-api-passthrough/trees?gml_id=eq.${gml_id}`,
			{
				method: "POST",
				headers: {
					Authorization: `Bearer ${anon_token}`,
				},
			},
		);
		if (!response.ok) {
			const txt = await response.text();
			console.error(txt);
			throw new Error(txt);
		}
		const json = await response.json();
		return json;
	}

	main().then(console.log).catch(console.error);
}

For the nowcast and forcast routes/tables you will have to pass a baum_id with each request.

curl -L -X POST 'https://[abcdefghijklmnopqrst].functions.supabase.co/ml-api-passthrough/nowcast?baum_id=eq.1' -H 'Authorization: Bearer [YOUR ANON KEY]'

Tests

None yet :(

Contributing

Contributors

Thanks goes to these wonderful people (emoji key):


Fabian Morón Zirfas

📖

Lucas Vogel

📖 🤔 👀 💻

Ingo Hinterding

📖

This project follows the all-contributors specification. Contributions of any kind welcome!

Content Licensing

Texts and content available as CC BY.

Illustrations by Maria Musterfrau, all rights reserved.

Credits

Made by

A project by

Supported by

Related Projects