Skip to content

rednblkx/parcel-romania-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Parcel Tracking App - Backend

This repository contains the serverless functions and database setup for the Parcel Tracking App, built with Supabase.

Features

  • Serverless functions implemented with Supabase Edge Functions
  • Two functions:
    • trace-parcel: Called from the frontend to get the data of the parcel from the carrier
    • parcel-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

Prerequisites

Installation

To set up the backend for the app, follow these steps:

  1. Install the Supabase CLI: Refer here
  2. Clone the repository: git clone https://github.com/redmusicxd/parcel-romania-backend.git
  3. Navigate to the project directory: cd parcel-romania-backend
  4. 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

Configuration

The backend requires the following environment variables to be set in order for the respective APIs to work:

  • FAN_USERNAME, FAN_PASSWORD, and FAN_CLIENTID for FAN Courier
  • CARGUS_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.

Setting up the cron job

To set up the cron job for the parcel-monitor function, run the query from the cronjob.sql file.

Deployment

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

Contributing

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

License

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