NodeJs API server that uses Cerbos for smooth authorization.
This is a ExpressJs application that provides a APIs for users to view and manage courses. It uses Cerbos for authorization.
-
Node.js – JavaScript runtime
-
Express – NodeJs Web application framework
-
Cerbos – Authorization Service
-
docker - Containerization platform
-
fly.io - Deployments
-
Git – versioning
-
Prerequisites
Make sure you have the Docker installed on your machine.
-
Clone the repository:
git clone https://github.com/rohitg00/fly-cerbos-demo.git
-
Navigate to the project directory:
cd node-cerbos-fly/server
-
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.
-
Start the services using Docker Compose from Root:
cd .. docker-compose up # then press 'w' to Enable Watch (For Hot Reloading)
-
Prerequisites
Make sure you have the following installed on your machine:
-
Clone the repository:
git clone https://github.com/rohitg00/fly-cerbos-demo.git
-
Navigate to the project directory:
cd node-cerbos-fly
-
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
-
-
Deploy NodeJs App:
-
Navigate to the server directory in your terminal:
cd ../server
-
Add and update Environment Variables:
-
Open the fly.toml file, Copy
CERBOS_PDP_URL
-
Update the environment variables in
.env.prod.sample
, especially setCERBOS_PDP_URL
to the URL of your deployed Cerbos PDP instance. -
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
-
-
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.
-
Contributions are always welcome! Feel free to open issues or submit PRs.