From 8fbc0fbdac878464e32b18907402268d610de0ee Mon Sep 17 00:00:00 2001 From: Ryan Laughlin Date: Wed, 31 Mar 2021 05:15:52 -0400 Subject: [PATCH] Update development setup instructions (#313) * Add step about requiring patrons.json file * Update steps to get DB up and running * Clarify Discord login setup instructions * Clarify how to start/stop server for new developers * Update README to remove unneeded .env.local var Co-authored-by: Kalle <38327916+Sendouc@users.noreply.github.com> --- README.md | 26 +++++++++++++++++++------- prisma/scripts/preBuild.ts | 3 +++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 79a643185..4f82cdbe8 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,13 @@ With the following steps you can access a few pages that don't need a database. 1. Clone the project 2. Run `npm i` to install dependencies 3. Run `npm run compile` to compile translation files. -4. Run `npm run dev` to start the development server at http://localhost:3000/ +4. Run `npm run dev` to start the development server at http://localhost:3000/. (To stop the server at any time, type `Ctrl+C`.) + +If you do not intend to perform any additional setup steps, you will also need to create an empty list of patrons in `utils/data/patrons.json`: + +``` +[] +``` ### Access rest of the pages @@ -59,18 +65,19 @@ DATABASE_URL=postgresql://sendou@localhost:5432 _You can see [Prisma's guide on how to set up a PostgreSQL database running locally](https://www.prisma.io/dataguide/postgresql/setting-up-a-local-postgresql-database) for more info._ 6. Use `npm run migrate` to get the database formatted with the right tables. -7. Seed some example data in the database by running `npm run seed`. (This seed data is incomplete – see issue #197 if you would like to improve the seed data!) +7. Run `npm run prebuild` to generate a few necessary JSON configuration files. +8. Seed some example data in the database by running `npm run seed`. (This seed data is incomplete – see issue #197 if you would like to improve the seed data!) ### Enable logging in In addition to the steps above the steps below enable logging in. -7. Create a file called `.env.local` in the root folder. In it you need following variables: +9. Create a file called `.env.local` in the root folder. In it you need following variables: ``` -DISCORD_CLIENT_ID= -DISCORD_CLIENT_SECRET= -JWT_SECRET= +DISCORD_CLIENT_ID="" +DISCORD_CLIENT_SECRET="" +JWT_SECRET="" ``` a) Go to https://discord.com/developers/applications @@ -79,7 +86,12 @@ c) Go to your newly generated application d) On the "General Information" tab both "CLIENT ID" and "CLIENT SECRET" can be found. e) On the "OAuth2" tab add `http://localhost:3000/api/auth/callback/discord` in the list of redirects. -`JWT_SECRET` can be any randomly generated reasonably long string. +For `JWT_SECRET`, use a long, cryptographically random string. You can use `node` to generate such a string as follows: +``` +node -e "require('crypto').randomBytes(64, function(ex, buf) { console.log(buf.toString('base64')) })" +``` + +Make sure to restart your server after setting these new values (`Ctrl+C` + `npm run dev`). ## Using API diff --git a/prisma/scripts/preBuild.ts b/prisma/scripts/preBuild.ts index 36ff782d0..c11f208ad 100644 --- a/prisma/scripts/preBuild.ts +++ b/prisma/scripts/preBuild.ts @@ -2,6 +2,9 @@ import fs from "fs"; import path from "path"; import prisma from "../client"; +// Include Prisma's .env file as well, so we can fetch the DATABASE_URL +require('dotenv').config({path: 'prisma/.env'}); + const main = async () => { const patrons = await prisma.user.findMany({ where: { patreonTier: { not: null } },