topcoder-platform / timeline-wall-api

Topcoder timeline wall back end APIs and support code
0 stars 1 forks source link

Topcoder Timeline Wall Backend

This project contains the backend for Topcoder Timeline Wall.

Environment Variables

To set the environment variables, create a .env file with the following variables (to be filled):

# The port used by the server
SERVER_PORT=

# Configuration for token verification
AUTH_SECRET=
VALID_ISSUERS=

# List of admins (handles, space-separated)
ADMIN_USERS=

# Template of AWS bucket url
PHOTO_URL_TEMPLATE=

# AWS S3 bucket info
S3_API_VERSION=
AWS_REGION=
AWS_SECRET_ACCESS_KEY=
AWS_ACCESS_KEY_ID=
BUCKET_NAME=

# PostgreSQL info
DB_USER=postgres
DB_PASSWORD=postgres
DB_HOST=localhost
DB_NAME=topcoder-timeline
DB_PORT=

# Bus API (used to send emails)
BUSAPI_URL=
EVENT_APPROVED_TEMPLATE_ID=
EVENT_REJECTED_TEMPLATE_ID=
MEMBER_API_BASE_URL=
EMAIL_FROM=

# Auth0 info (for accessing member api)
AUTH0_URL=
AUTH0_AUDIENCE=
TOKEN_CACHE_TIME=
AUTH0_CLIENT_ID=
AUTH0_CLIENT_SECRET=

# Kafka error topic for bus API
KAFKA_ERROR_TOPIC=

# max dimensions of preview photos
PREVIEW_MAX_WIDTH=
PREVIEW_MAX_HEIGHT=

# Maximum size for a single media file (infinity if undefined)
MEDIA_SIZE_LIMIT=

Execute

You can start the server by running npm start, or in developer mode by running npm run dev.

Run in Docker

When using docker, you can run the Dockerfile located in the root folder to run only the server. Alternatively, you can use the docker-compose file (docker-compose up) to run both the server and the postgres database in Docker. In this case the postgres database will also execute the SQL scripts located at /docs.

Run aws bucket locally

To run the aws bucket locally in docker (using minio), you can run the docker-compose file located in /local. In this case, you need to add the following lines to the .env file:

IS_LOCAL_DB=true
AWS_ENDPOINT=http://localhost:9000

Note that if you want to connect to the local AWS bucket from within a docker container, you should change AWS_ENDPOINT to 'http://host.docker.internal:9000'

After starting the minio server, you must open the console on localhost:9091. The username and password are:

Then, create a new bucket with the name that was specified in the .env file of the server and set its visibility to public.

Sending Emails with Bus API

The templates for the emails are located at /email_templates.

Once the templates are loaded into sendgrid, you must set the templates ID in .env:

EVENT_APPROVED_TEMPLATE_ID=
EVENT_REJECTED_TEMPLATE_ID=

You can also set up the notification types strings from /constants.js.

Setup Admin users

The admin users can be defined as a string of space-separated handles, in the .env file:

ADMIN_USERS=

Postman Testing

You can import the Postman environment and collection from /docs. Remember to set the bearer_token to the token used for authentication. The base url is by default localhost:3000. You can change it also in the postman environment.