Mugsy

View Original

DECAF Quickie

Hey folks, hope all is well. I started pushing the initial DECAF setup to the Org repo. As mentioned previously, this is just the basic app set up, with auth, user creation, and login endpoints. Additional endpoints will be continually added over the next week or two as they are tested and cleaned up as needed.

You can find the repo here: https://github.com/MugsyOS/DECAF

You can clone the repo and spin it up by following these steps:

  • Clone the repo:

    • git clone https://github.com/MugsyOS/DECAF.git
  • cd into the directory

  • Install the app and libraries:

    • npm install
  • rename env.template to .env

  • fill out the following settings:

    • DB_PATH: This is where the db will be stored, for dev, ./database.sqlite is fine.

    • JWT_SECRET: I have included a utility to simplify generating a secret. Just run the following command and copy the result into the .env file:

      • npm run generate-secret
    • Fill out the remaining details with your preferred admin user details.

    • save the file

  • Create the database and migrate to the current schema:

    • npx drizzle-kit migrate
  • Seed the admin user:

    • npm run create-admin-user
  • Run all tests:

    • npm run test

After that you can test the endpoints using your preferred REST client like Postman. I will have API docs soon, but for now here are the basic endpoints you can access:

Login Endpoint: POST localhost:3000/api/v1/login

  • Method: POST

  • Payload:

    { "username": "your-username", "password": "your-password" }

On successful login, DECAF will return an authentication token. You will need to add this as a Bearer token in Postman’s auth tab for the remaining endpoints.

Register Standard User

  • Endpoint: POST localhost:3000/api/v1/users/register

  • Method: POST

  • Authentication: Bearer token

  • Payload:

    • { "username": "yourUsername", "password": "yourPassword" }

I’ve also added a test entity table (cats) you can add items to:

Create Cat

  • Endpoint: POST localhost:3000/api/v1/cats

  • Method: POST

  • Authentication: Bearer token

  • Payload:

    • { "name": "Princess Donut", "type": "Royal Chungus" }

Get Cats

  • Endpoint: GET localhost:3000/api/v1/cats

  • Method: GET

  • Authentication: Bearer token

  • Payload: None

Please note that beyond endpoints, some things like the error middleware, proper CORS setup, and more config level items have not been pushed. That being said, minus those items, this setup is very close to what will be running on prod.

Apologies for the limited docs at this time, will have a deeper dive into the DECAF set up later this week.

Cheers!