@eheikes/oscar-api
v0.1.0
Published
OSCAR assistant API
Downloads
2
Readme
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.test
for 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.pem
file in thisapi
folder. - Rename
.env.example
to.env
and update it with your configuration, or set those variables in your environment.- Make sure
NODE_ENV
is not set todevelopment
.
- Make sure
- Run
npm install && npm run build:release && ARN=YOUR_ARN npm run release
.- Replace
YOUR_ARN
with 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:release
to 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.test
to 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.