Skip to content

Commit

Permalink
Update README: listed required env var vs. optional
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleecodes committed Oct 18, 2023
1 parent 76cfee3 commit c10884c
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 69 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions .vscode/extensions.json

This file was deleted.

27 changes: 0 additions & 27 deletions .vscode/settings.json

This file was deleted.

4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# First stage: build server app
FROM node:12 as builder
FROM node:14 as builder
ENV NODE_ENV=development
WORKDIR /app
COPY . .
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 ./
Expand Down
100 changes: 70 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:

Expand All @@ -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.

Expand All @@ -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
Expand Down Expand Up @@ -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: <https://docs.docker.com/get-docker/>.
**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: <https://docs.docker.com/get-docker/>.
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:

Expand All @@ -170,3 +202,11 @@ curl -v http://localhost:3000/api/resources
```

… or opening the URL <http://localhost:3000/api/resources> 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.

0 comments on commit c10884c

Please sign in to comment.