non-fungible-apps/serverless
Shredder d838f1a449
feat: MongoDB & Prisma [serverless] (#224)
* feat: init prisma.

* feat: update the prisma model.

* feat: write client tests.

* feat: Prisma integration and helper [serverless] (#229)

* refactor: rename the prisma folder to prisma-setup.

* feat: install prisma client.

* feat: add new build and invoke commands for prisma and the modules.

* feat: add prisma helper, update serverless config for testing purposes

* docs: update readme and include a .env.example file.

* feat: zoruka's suggestion on using finally instead of catch.

Co-authored-by: Felipe Mendes <zo.fmendes@gmail.com>

---------

Co-authored-by: Felipe Mendes <zo.fmendes@gmail.com>

* feat: prisma-setup restructure.

---------

Co-authored-by: Felipe Mendes <zo.fmendes@gmail.com>
2023-04-27 15:01:21 +03:30
..
examples/client feat: MongoDB & Prisma [serverless] (#224) 2023-04-27 15:01:21 +03:30
prisma feat: MongoDB & Prisma [serverless] (#224) 2023-04-27 15:01:21 +03:30
src feat: MongoDB & Prisma [serverless] (#224) 2023-04-27 15:01:21 +03:30
.env.example feat: MongoDB & Prisma [serverless] (#224) 2023-04-27 15:01:21 +03:30
.gitignore feat: serverless new mint handler placeholder (#221) 2023-04-25 22:09:54 +03:30
README.md feat: MongoDB & Prisma [serverless] (#224) 2023-04-27 15:01:21 +03:30
package.json feat: MongoDB & Prisma [serverless] (#224) 2023-04-27 15:01:21 +03:30
serverless.yaml feat: MongoDB & Prisma [serverless] (#224) 2023-04-27 15:01:21 +03:30
tsconfig.json feat: MongoDB & Prisma [serverless] (#224) 2023-04-27 15:01:21 +03:30
yarn.lock feat: MongoDB & Prisma [serverless] (#224) 2023-04-27 15:01:21 +03:30

README.md

NFA - Serverless

Requirements

This sub-project of NFAs requires Node 18. Specifically, this has been tested with 18.13.0 so far.

Setup

After cloning the repo, ensure you run yarn in the root directory. After that, cd into the serverless directory and alsy run yarn.

If you are deploying, make sure you have your AWS credentials set to environment variables or have setup AWS credentials using the AWS CLI. Please refer to the official AWS documentation here to see all the ways to set these credentials.

Basically, these values need to be set:

export AWS_ACCESS_KEY_ID=value
export AWS_SECRET_ACCESS_KEY=value
export AWS_SESSION_TOKEN=value

You can get these from the main screen after logging in.

Running and Testing

You first build the code by running yarn build. This will produce the bundle file in the dist directory.

TODO: yarn test

To run locally, use SLS_DEBUG=* yarn sls offline --verbose. You can then hit the endpoints displayed in the console using curl, postman or any HTTP client.

Deploying

To deploy, make sure you have AWS credentials set in your local environment.

To deploy to development environment: yarn sls deploy --stage dev

To deploy to production environment: yarn sls deploy --stage prd

Prisma configuration

In order to use and integrate Prisma, both of the prisma and @prisma/client packages are needed. The prisma package reads the schema and generates a version of Prisma Client that is tailored to our modules.

Run the following commands to install the packages and generate the customized Prisma Client version based on the schema:

yarn add prisma @prisma/client
yarn prisma:generate