Skip to content

cerbos/fly-cerbos-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

NodeJs + Cerbos Demo

NodeJs API server that uses Cerbos for smooth authorization.


Introduction

This is a ExpressJs application that provides a APIs for users to view and manage courses. It uses Cerbos for authorization.


Tech Stack

  • Node.js – JavaScript runtime

  • Express – NodeJs Web application framework

  • Cerbos – Authorization Service

  • docker - Containerization platform

  • fly.io - Deployments

  • Git – versioning


🐳   Run with Docker locally

  1. Prerequisites

    Make sure you have the Docker installed on your machine.

  2. Clone the repository:

    git clone https://github.com/rohitg00/fly-cerbos-demo.git
  3. Navigate to the project directory:

    cd node-cerbos-fly/server
  4. Add Environment Variables:

    Create .env file in the root folder and copy paste the content of .env.sample.

    cp .env.sample .env

    If required, add/replace credentials.

  5. Start the services using Docker Compose from Root:

    cd ..
    docker-compose up
    
    # then press 'w' to Enable Watch (For Hot Reloading)

Deployemnt Setup

  1. Prerequisites

    Make sure you have the following installed on your machine:

  2. Clone the repository:

    git clone https://github.com/rohitg00/fly-cerbos-demo.git
  3. Navigate to the project directory:

    cd node-cerbos-fly
  4. Deploy Cerbos PDP:

    • Navigate to the cerbos directory in your terminal:

      cd cerbos
    • Use Fly Launch to quickly deploy PDP instance using a Docker image. :

      flyctl launch
  5. Deploy NodeJs App:

    • Navigate to the server directory in your terminal:

      cd ../server
    • Add and update Environment Variables:

      1. Open the fly.toml file, Copy CERBOS_PDP_URL

      2. Update the environment variables in .env.prod.sample, especially set CERBOS_PDP_URL to the URL of your deployed Cerbos PDP instance.

      3. Create .env file in the root folder and copy paste the content of .env.prod.sample.

      cp .env.prod.sample .env
    • Use Fly Launch to quickly deploy NodeJs api sever using a Docker image. :

      flyctl launch
  6. Testing APIs using Postman

    • Open Postman

    • Import this collection.

    • Replace the URL in each request with the URL of your Node.js server.

    • Access the courses and test whether the authorization logic is working properly.


Contributing

Contributions are always welcome! Feel free to open issues or submit PRs.

About

No description, website, or topics provided.

Resources

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •