This repository contains the serverless functions and database setup for the Parcel Tracking App, built with Supabase.
- Serverless functions implemented with Supabase Edge Functions
- Two functions:
trace-parcel
: Called from the frontend to get the data of the parcel from the carrierparcel-monitor
: Called from the pg_cron extension using a service role API key to bypass the row level security policies
- Setup for a supabase PostgreSQL database with tables and row level security policies
- Cron job that runs
parcel-monitor
every 31 minutes to check for updates on the parcels and sending notifications via ntfy.sh - OAuth authentication with Google
- Node.js and npm or yarn installed
- The Supabase CLI and docker set up: supabase.com/docs/getting-started/install
To set up the backend for the app, follow these steps:
- Install the Supabase CLI: Refer here
- Clone the repository:
git clone https://github.com/redmusicxd/parcel-romania-backend.git
- Navigate to the project directory:
cd parcel-romania-backend
- Set up the supabase project:
- Create a new supabase project and database at supabase.com
- Have a look here for the requirements reagrding local development with supabase
- Push the migrations of the database:
supabase db push
- Enable Google as Auth Provider: have a look here or here
- Start the supabase docker containers:
supabase start
- Set the environment variables as below
- Run the
trace-parcel
function:supabase functions serve --no-verify-jwt --env-file .env trace-parcel
At the time of writing this, functions cannot be run locally in parallel, meaning only one can run at any given time
The backend requires the following environment variables to be set in order for the respective APIs to work:
FAN_USERNAME
,FAN_PASSWORD
, andFAN_CLIENTID
for FAN CourierCARGUS_APIKEY
for Cargus
Note that SUPABASE_KEY
and SUPABASE_URL
are being provided automatically inside the functions by the supabase environment
These environment variables are stored in a .env file in the root of the project. Make sure to set these variables before running the database setup script or deploying the functions.
To set up the cron job for the parcel-monitor
function, run the query from the cronjob.sql
file.
To deploy the serverless functions to supabase, run the following commands:
- Deploy the
trace-parcel
function:supabase functions deploy --no-verify-jwt trace-parcel
- Deploy the
parcel-monitor
function:supabase functions deploy --no-verify-jwt parcel-monitor
Contributions are welcomed to the Parcel Tracking App backend. If you would like to contribute, please follow these guidelines:
- Fork the repository and create a new branch for your changes
- Make your changes and commit them with a descriptive commit message
- Open a pull request, explaining the changes you made and the problem they solve
The Parcel Tracking App backend is licensed under the MIT License.
This README.md was generated by OpenAI's ChatGPT with some mild brushing in order to adapt to the latest changes from supabase