Skip to content

Setup Guide

Logan Van Hook edited this page Jan 4, 2021 · 8 revisions

Back End Setup Guide

  1. Clone BE repository and run npm install -D to install all required dependencies

  2. Create Docker PostgreSQL container. Skip this step if you have already installed PostgreSQL/pgAdmin locally.

    • Use docker pull postgres:12.1-alpine to download image.
      PostgreSQL Docker image - https://hub.docker.com/_/postgres
    • Run image using the following command:
      docker run --name ss-postgres --publish 5432:5432 postgres:12.1-alpine
      (12.1-alpine is the current version as of 3.12.20.
      It may be a different version now. Use the above link to check version and change run command as needed)
  3. Add the following environment variables in a .env file, Note that the DATABASE_URL needs to match your local database settings, protocol://username:password@address:port/postgres

    PORT=5000
    JWT_SECRET=Its a secret (example - create your own)
    SECRET_SIGNATURE=Its a secret (example - create your own)
    DATABASE_URL=postgresql://postgres:1234@localhost:5432/postgres 
    AWS_ACCESS_KEY='THE_EMAIL_AND_IMAGE_UPLOAD_SERVICE_AWS_ACCESS_KEY'
    AWS_SECRET_KEY='THE_EMAIL_AND_IMAGE_UPLOAD_SERVICE_AWS_SECRET_KEY'
    BE_ENV=development
    DS_API_URL=DS API URL
    DS_API_KEY=DS API Key
    
  4. Run migrations and seeds using the following commands:

    • npm run latest
    • npm run seed
  5. Start backend npm start - nodemon can be used, but may crash during image-upload from the Google-Vision library.

Need a prompt immediately?

These instructions will help you quickly edit the database to get an active-prompt so you can submit ASAP without running the startGame function. (Due to the S3 Security settings, you cannot submit an image locally without letting us know so we can add your information!)

  1. Navigate to PGAdmin
  2. Under the database, open tables, then view all rows for prompts
  3. Set one prompt to active=true (for this example set prompt id 6) and click save (the table icon)
  4. Right click the prompt_queue table and open "Query-Tool"
  5. In the textbox, write: UPDATE prompt_queue SET queue = '6'; and click the play button.
  6. You should now have an active-prompt to submit to

Adding an administrator

For an account to have administrative route permissions, they must exist in the admins table. This table does not have an index, so you must query the id in similar to the following: INSERT INTO admins (uid) VALUES (<uid>) which will then allow signed tokens from that user to have access to admin-restricted routes.

Useful Commands

  • npm run server/go to start the local server with auto restart on change - (May crash on image uploads)
  • npm run start to start production version (Regular node)
  • npm run rollback revert running most recent migration(s)
  • npm run latest migrate database to the latest schema
  • npm run seed wipe database and write seed data
  • npm run dev wipe the database, migrate latest, run seeds
Clone this wiki locally