0.1.0 • Published 1 year ago
@eheikes/oscar-api v0.1.0
OSCAR API Server
This project contains the API server for the OSCAR assistant. It is written for AWS Lambda and RDS.
Installation & Usage
- Create a Postgres DB in AWS RDS
- Create the schemas defined in
test/mocks/postgres.
- Create the schemas defined in
- Create a serverless instance in AWS Lambda
- Set the handler to
index.handler. - Set the required environment variables under
Configuration -> Environment variables. See.env.testfor the list of variables and examples. - Set up an API gateway as the trigger.
- Set the handler to
- Download the AWS RDS certificate bundle for your region and replace the
rds-ca-bundle.pemfile in thisapifolder. - Rename
.env.exampleto.envand update it with your configuration, or set those variables in your environment.- Make sure
NODE_ENVis not set todevelopment.
- Make sure
- Run
npm install && npm run build:release && ARN=YOUR_ARN npm run release.- Replace
YOUR_ARNwith the ARN of your Lambda instance.
- Replace
API Reference
Coming soon
Development
Remember to set your environment variables (using .env or other method) to configure the app. Set a NODE_ENV environment variable to development for debugging.
Scripts for local development:
- Run a local server:
npm start. - Lint the files:
npm run lint. - Build the app:
npm run build. Runnpm run build:releaseto minify the files. - Upload & publish to AWS Lambda:
ARN=<LAMBDA ARN> npm run release- Replace
<LAMBDA ARN>with your Lambda function's ARN.
- Replace
For running automated tests:
- To run all tests:
npm run test. This needs to be set up for both unit and E2E tests as described below. - To run unit tests:
npm run test:unit. - To run end-to-end tests:
- Start a local Postgres server. You can run a temporary server with Docker using something like
docker run -v ./test/mocks/postgres:/docker-entrypoint-initdb.d -e POSTGRES_PASSWORD=test -d -p 5432:5432 postgres. - Update
.env.testto match the database credentials. - Run
npm run test:e2e.
- Start a local Postgres server. You can run a temporary server with Docker using something like
Dev Troubleshooting
npm start crashes with uncaught exception
If you see:
node:internal/process/esm_loader:46
internalBinding('errors').triggerUncaughtException(
^
[Object: null prototype] {
[Symbol(nodejs.util.inspect.custom)]: [Function: [nodejs.util.inspect.custom]]
}It's probably a problem with the types. Run npm run build to see the error.
DB query isn't working
Add DEBUG=knex:query to your command to print out the Knex SQL queries.
0.1.0
1 year ago