From c10884c0980e02b715647f3d02a145e93f7ea875 Mon Sep 17 00:00:00 2001 From: kyleecodes Date: Tue, 17 Oct 2023 21:49:39 -0400 Subject: [PATCH] Update README: listed required env var vs. optional --- .gitignore | 4 +- .vscode/extensions.json | 8 ---- .vscode/settings.json | 27 ----------- Dockerfile | 4 +- README.md | 100 ++++++++++++++++++++++++++++------------ 5 files changed, 74 insertions(+), 69 deletions(-) delete mode 100644 .vscode/extensions.json delete mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 8106a43..21b23c4 100644 --- a/.gitignore +++ b/.gitignore @@ -27,14 +27,14 @@ lerna-debug.log* *.sublime-workspace # IDE - VSCode -.vscode/* +/.vscode !.vscode/settings.json !.vscode/tasks.json !.vscode/launch.json !.vscode/extensions.json +# Local env files .env.local -.env .env.development .env.development.local .env.test.local diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index 9433034..0000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"], - "unwantedRecommendations": [ - "hookyqr.beautify", - "dbaeumer.jshint", - "ms-vscode.vscode-typescript-tslint-plugin" - ] -} diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 5cdeed2..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "javascript.format.enable": false, - "javascript.validate.enable": false, - "typescript.format.enable": false, - "eslint.enable": true, - "eslint.format.enable": true, - "eslint.packageManager": "yarn", - "eslint.alwaysShowStatus": true, - "eslint.validate": ["typescript", "javascript"], - "[javascript]": { - "editor.defaultFormatter": "dbaeumer.vscode-eslint" - }, - "[typescript]": { - "editor.defaultFormatter": "dbaeumer.vscode-eslint" - }, - "[json]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, - "editor.formatOnPaste": true, - "editor.formatOnSave": true, - "editor.formatOnType": true, - "editor.codeActionsOnSave": { - "source.organizeImports": true, - "source.fixAll": true - }, - "typescript.tsdk": "node_modules/typescript/lib" -} diff --git a/Dockerfile b/Dockerfile index b67a73f..88fbdb4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # First stage: build server app -FROM node:12 as builder +FROM node:14 as builder ENV NODE_ENV=development WORKDIR /app COPY . . @@ -7,7 +7,7 @@ RUN yarn install --frozen-lockfile --non-interactive RUN yarn build # Second stage: leaner image to deploy and run the built app -FROM node:12-alpine +FROM node:14-alpine ENV NODE_ENV=production WORKDIR /app COPY --from=builder /app/package.json /app/yarn.lock ./ diff --git a/README.md b/README.md index 7ce79d9..5402f23 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,10 @@ -# YSM Backend - -![GitHub Actions CI workflow badge](https://github.com/chaynHQ/ysm-backend/workflows/YSM%20Backend%20CI%20pipeline/badge.svg) +# Your Story Matters (YSM) Your Story Matters (YSM) is a digital companion for survivors of sexual assault launched in 2019. Formerly called YANA (You Are Not Alone) and funded by Nesta and the UK Department of Digital, Culture, Media and Sport through the Tech to Connect Challenge, YSM has curated content including recovery, moving through trauma, accessing justice through the law, stories of resilience, and allows survivors the option to create an account and save their journey. -**Currently in active development.** - ## Get Involved -If you would like to help Chayn and receive special access to our organization and volunteer opportunities, please [visit our Getting Involved guide](https://chayn.notion.site/Get-involved-423c067536f3426a88005de68f0cab19). We'll get back to you to schedule an onboarding call. Other ways to get involved and support us are [donating](https://www.paypal.me/chaynhq), starring this repo and making an open-source contribution here on GitHub, and supporting us on social media! +If you would like to help Chayn and receive special access to our organization and volunteer opportunities, please [visit our Getting Involved guide](https://chayn.notion.site/Get-involved-423c067536f3426a88005de68f0cab19). We'll get back to you to schedule an onboarding call. Other ways to get involved and support us are [donating](https://www.paypal.me/chaynhq), starring this repo and making an open-source contribution here on GitHub, and supporting us on social media! Our social medias: @@ -22,41 +18,82 @@ Youtube - [Chayn Team](https://www.youtube.com/channel/UC5_1Ci2SWVjmbeH8_USm-Bg) LinkedIn - [@chayn](https://www.linkedin.com/company/chayn) - # YSM Backend -A [NestJS](https://nestjs.com/) API server with [Jest](https://jestjs.io/) testing. +![GitHub Actions CI workflow badge](https://github.com/chaynHQ/ysm-backend/workflows/YSM%20Backend%20CI%20pipeline/badge.svg) + +A NestJS API server with Jest testing. + +This repo serves just the YSM backend, find YSM's frontend code here: https://github.com/chaynHQ/ysm + +**Currently in active development.** + +## How to Contribute: + +Before making a contribution, please follow our Contributing Guidelines in [CONTRIBUTING.md](/CONTRIBUTING.md). + +Happy coding! ⭐ ## Development -Note: if you just want to run the backend service locally and not do any development work on it, you can instead skip to the section on how to run it in a Docker container. +**RECOMMENDED: You may skip ahead to the [Running as a Docker Container Locally section below](#running-as-a-docker-container-locally) if you just want to run the backend service locally and not do any development work on it.** ### Prerequisites -- NodeJS v12+ +- NodeJS v14+ - Yarn v1.21+ +### Technologies Used: + +- [NestJS](https://nestjs.com/) - Node.js web framework +- [Jest](https://jestjs.io/) - JavaScript testing +- [Firebase](https://firebase.google.com/) - user authentication and analytics +- [Rollbar](https://rollbar.com/) - error reporting +- [StoryBlok](https://www.storyblok.com/) - headless CMS for pages and courses content +- [Heroku](https://www.heroku.com/) - build, deploy and operate staging and production apps +- [GitHub Actions](https://github.com/features/actions) - CI pipeline + ### Set up local env config -Certain config values are required to run the server. +For local development, create a new **`.env.development`** file and add the following environment variables: -For local development, create a new **`.env.development`** file and add in the following: +If you're an official Chayn volunteer, please get in touch with the team for access to the environment variables. -```shell -STORYBLOK_TOKEN={value} # The API token from Storyblok (must have 'draft' access) +``` +# The API token from Storyblok (must have 'draft' access) +STORYBLOK_TOKEN= + +# The service account JSON object serialised into a string and then base64 encoded +FIREBASE_SERVICE_ACCOUNT={value} -FIREBASE_SERVICE_ACCOUNT={value} # The service account JSON object serialised into a string and then base64 encoded +# OPTIONAL: comma separated list of email addresses for users allowed to access preview mode (for viewing draft content from Storyblok) +CONTENT_EDITOR_EMAILS= -CONTENT_EDITOR_EMAILS={value} # Optional. A comma separated list of email addresses of the users that are allowed to access preview mode (for viewing draft content from Storyblok) +# OPTIONAL: when running in `dev` mode. Either set this to the Rollbar server token, or to `false` to disable. +ROLLBAR_TOKEN={value} -ROLLBAR_TOKEN={value} # Optional when running in `dev` mode. Either set this to the Rollbar server token, or to `false` to disable. -ROLLBAR_ENV=local-dev # Required in `production` mode or if `ROLLBAR_TOKEN` is set. +# OPTIONAL: required in `production` mode or if `ROLLBAR_TOKEN` is set. +ROLLBAR_ENV=local-dev -RATE_LIMIT_WINDOW_MS={value} # Optional. The window of time (in milliseconds) for the rate limiting to apply. -RATE_LIMIT_MAX=(value) # Optional. The max number of requests (per IP address) within the window of time (above). +# OPTIONAL: The window of time (in milliseconds) for the rate limiting to apply. +RATE_LIMIT_WINDOW_MS={value} + +# OPTIONAL: The max number of requests (per IP address) within the window of time (above). +RATE_LIMIT_MAX=(value) +``` + +**If creating new environment variables:** + +- Check if the new environment variable must be added the [ci.yml](.github/workflows/ci.yml) file. +- Note that new environment variables must be added to Heroku before release to production. Please tag staff in your issue if creating new environment variables. + +### Install dependencies + +```bash +yarn ``` -#### Env config for tests +### Set up local env config for tests Tests will use a separate `.env.test` file which should already be present. @@ -72,12 +109,6 @@ FIREBASE_SERVICE_ACCOUNT={value} # Same as in .env.development - the service ac FIREBASE_WEB_API_KEY={value} # Special API key just for use in e2e tests - found in the settings page for the Firebase project ``` -### Install dependencies - -```bash -yarn -``` - ### Run locally ```bash @@ -140,16 +171,17 @@ DEBUG=axios yarn start:dev Note: the `axios-debug-log` library used to provide this logging has only been added as a dev dependency, so this will not work in production environments. -## Running as a Docker container locally +# Running as a Docker Container Locally You may want to run the backend service in a Docker container if: 1. You don't intend to do any development work on it and just need a running service for the frontend to access. 1. You want to test that the Docker image works as expected, e.g. if you've made any changes to the `Dockerfile`. -First, ensure you have the Docker service installed and running on your machine. More info on how to do this: . +**Steps to run the docker container locally:** -Then, follow the section on setting up your local env config, above. Note that you don't need to follow any other instructions from the previous sections (like having the prerequisites, installing dependencies, etc.) as the Docker build process will do all this for you. +1. Ensure you have the Docker service installed and running on your machine. More info on how to do this: . +2. Follow the directions above on [setting up your local env config](#set-up-local-env-config). Note that you don't need to follow any other instructions from the previous sections (like having the prerequisites, installing dependencies, etc.) as the Docker build process will do all this for you. Then, build the image: @@ -170,3 +202,11 @@ curl -v http://localhost:3000/api/resources ``` … or opening the URL in your browser. It should show the JSON output of the `/resources` API. + +# License + +This project uses the [MIT License](/LICENSE). + +YSM and all of Chayn's projects are open-source. + +While the core tech stack included here is open-source, some external integrations used in this project may require subscriptions.