Skip to content
Michał Plebański edited this page May 14, 2021 · 4 revisions

NestJS backend

Install dependencies (instructions are for MacOS)

  1. Install Node.js 12.x and Yarn package manager:
brew install node@12. yarn
  1. Install redis by following the instructions here.
  2. Install Postgres 12 DB:
brew install postgresql@12

and create a new database called bloom.

psql -c 'CREATE DATABASE bloom;`
  1. Clone this repository:
git clone https://github.com/bloom-housing/bloom.git
  1. Install project dependencies
cd backend/core && yarn install

Configure environment

1 . Define environment variables for local based on a provided template:

# backend/core workdir
cp .env.template .env

and edit .env according to your needs.

Name Description Default Type
PORT Defines port number the server will listen to for incoming connections. 3100 number
NODE_ENV Controls build optimization and enables some additional logging when set to development development "development" | "production"
DATABASE_URL Database connection string postgres://localhost/bloom string
REDIS_TLS_URL Secure Redis connection string string
REDIS_URL TCP Redis connection string redis://127.0.0.1:6379/0
REDIS_USE_TLS Flag controlling the use of TLS or unsecure transport for Redis 0 0 | 1
THROTTLE_TTL Rate limit TTL in seconds (currently used only for application submission endpoint) 60 number
THROTTLE_LIMIT Max number of operations in given time window THROTTLE_TTL after which HTTP 429 Too Many Requests will be returned by the server 2 number
EMAIL_API_KEY Sendgrid API key (see sendgrid docs for creating API keys SOME-LONG-SECRET-KEY string
EMAIL_FROM_ADDRESS Controls "from" field of all the emails sent by the process 'Bloom Dev Housing Portal bloom-no-reply@exygy.dev' string
APP_SECRET Secret used for signing JWT tokens (generate it with e.g. openssl rand -hex 48) SOME-LONG-SECRET-KEY string

Migrate and seed the DB

  1. Migrate the DB to latest schema:
    # backend/core workdir
    yarn run db:migration:run
    
  2. (Optional) Seed the database
    yarn db:migration:seed
    
    This step will create example listings, admin@example.com:abcdef admin user account, leasing agents user accounts etc.

Running the server

Development:

yarn run dev

Production:

yarn run build && yarn run start

Verifying if your setup works:

Go to localhost:3100/docs page and see if you can e.g. log in using /auth/login endpoint using following payload:

{
  "email": "admin@example.com",
  "password": "abcdef"
}

To play with other endpoints that require authentication copy paste the access token from the response to above query into the "Authorize" popup at the top of the page.

Public site

Requirements

  • running NestJS backend on localhost:3100

Install dependencies

  1. Install project dependencies
cd sites/public && yarn install

Configure environment

1 . Define environment variables for local based on a provided template:

# sites/public workdir
cp .env.template .env

and edit .env according to your needs.

Name Description Default Type
BACKEND_API_BASE URL pointing to a working NestJS bloom server (no trailing slash) http://localhost:3100 string
LISTINGS_QUERY Value specifying what path to use to fetch listings at build time for static serving /listings string
HOUSING_COUNSELOR_SERVICE_URL TODO https://housing.sfgov.org/assets/housing_counselors-7b0f260dac22dfa20871edd36135b62f1a25a9dad78faf2cf8e8e2514b80cf61.json string
NEXTJS_PORT Defines port number the server will listen to for incoming connections 3000 number
MAPBOX_TOKEN Mapbox access token used for interacting with maps. See more documentation here redis://127.0.0.1:6379/0 string
LANGUAGES Controls what languages Next will try to render on the page en,es,zh,vi string
IDLE_TIMEOUT TODO is it used anywhere? number
COUNTY_CODE Defines an identifier this site will send along with XHR requests for the backend to identify is as an appropriate county. At the moment affects only copy of the emails that are sent backend side. Alameda "Alameda" | "San Jose" | "San Mateo"
GTM_KEY Refer to analytics docs GTM-KF22FJP string

Running the server

Development:

# sites/public workdir
yarn run dev

Production:

# sites/public workdir
yarn run build && yarn run export

directory out/ now contains the statically built page.

Partners portal

Requirements

  • running NestJS backend on localhost:3100

Install dependencies

  1. Install project dependencies
cd sites/partners && yarn install

Configure environment

1 . Define environment variables for local based on a provided template:

# sites/partners workdir
cp .env.template .env

and edit .env according to your needs.

Name Description Default Type
BACKEND_API_BASE URL pointing to a working NestJS bloom server (no trailing slash) http://localhost:3100 string
NEXTJS_PORT Defines port number the server will listen to for incoming connections 3001 number
LISTINGS_QUERY Value specifying what path to use to fetch listings at build time for static serving (?) /listings string

Running the server

Development:

# sites/partners workdir
yarn run dev

Production:

# sites/partners workdir
yarn run build && yarn run export

directory out/ now contains the statically built page.