You'll need Node >= 8.x and npm to be installed.
You'll need to be running MySQL and SimpleSAMLphp. In development, our preferred method is to run them using Docker.
- Install dependencies:
npm install
- Copy the default environment variables:
cp .env-sample .env
- Generate keys for JWT authentication:
npm run keygen
- Build & start the MySQL and SimpleSAMLphp Docker containers:
cd docker && docker-compose up -d && cd ..
- Copy the test SAML IDP's Cert into
keys/idp_cert.pem
. You can find it here: https://github.com/kristophjunge/docker-test-saml-idp/blob/master/config/simplesamlphp/server.crt - Migrate the database:
npm run migrate
- [Optional] Seed the database with users & demo data:
npm run seed
- Start the server:
npm run start
- The API will now be running on
http://localhost:3000
- You can visit
http://localhost:3000/graphiql
to use our interactive GraphQL playground or send requests tohttp://localhost:3000/graphql
using your favorite HTTP client
server.js
- Sets up Express serverschema.js
- GraphQL Schemabin/
- Entrypoint for Backpackconfig/
- Configuration (eg. env variables, paths, SAML)db/
- Database migrations & seedsdocker/
- Development Docker containershelpers/
- Utility functionsmiddleware/
- Express request middlewaremodels/
- Sequelize modelsresolvers/
- GraphQL query, mutation, and type resolversroutes/
- Express REST endpoints (mainly for upload / download)test/
- Testsuploads/
- Where file uploads will be stored
To run the server and have it watch for changes, run npm run watch
.
ESLint is setup to warn you about style violations. You can run npm run lint
to check for style violations.
To run tests, run npm run test
. To run an individual test, run npm run test-file
with the path of the individual test file.
We use Mocha to run tests with the Chai assertion library. We use faker.js to generate fake test data and supertest to test endpoints. We use Istanbul to track code coverage.
We use Backpack to compile our application into a single file. To build the API for production, run npm run build
. This will create a build/
folder with a compiled main.js
output file.
You can then run this file with Node: node main.js
The frontend expects the API to be deployed to https://gallerygateway.rit.edu/backend
. We use nginx to proxy requests (and strip /backend
from incoming requests). You can find our nginx config in our deploy/
folder.
You'll need to have keys/
and uploads/
folders created relative to where you deploy the main.js
file. You'll have to create RSA keys for JWT authentication and provide the production SAML IDP Cert and put these in the keys/
folder. Any file uploads (and thumbnails) will be stored in the uploads/
folder.
The production MySQL database should be >= v5.7 and should be configured to use the utf8mb4
character-set. You can see an example configuration in our docker/
folder.
You can use npm run migrate
to migrate the MySQL database. If you need more sophisticated database management scripts (eg. rollback), run npm run sequelize
to access the Sequelize command-line tools.