freeCodeCamp/api
Oliver Eyton-Williams f6df0f3aed
docs: improve new api's mongodb setup guide (#50392)
* docs: improve new api's mongodb setup guide

* docs: give example variable

Co-authored-by: Naomi Carrigan <nhcarrigan@gmail.com>

* Update api/README.md

---------

Co-authored-by: Naomi Carrigan <nhcarrigan@gmail.com>
Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>
2023-05-16 20:04:41 +04:00
..
prisma chore(api): pull prod db schema (#49735) 2023-05-16 07:28:39 +03:00
src fix(tools): api settings test (#50394) 2023-05-16 07:32:17 +03:00
tools feat(api): add prisma as orm (#49413) 2023-03-14 17:29:55 +00:00
.gitignore chore(api): compile TS into /dist (#49812 2023-03-28 19:42:20 +05:30
jest.config.ts feat(api): add CORS headers (#50120) 2023-04-26 09:02:12 +02:00
jest.utils.ts chore(api): add test utilities (#50289) 2023-05-09 11:15:54 +05:30
package.json fix(deps): update dependency @fastify/middie to 8.3 (#50384) 2023-05-15 13:43:53 +03:00
README.md docs: improve new api's mongodb setup guide (#50392) 2023-05-16 20:04:41 +04:00
tsconfig.build.json chore(api): compile TS into /dist (#49812 2023-03-28 19:42:20 +05:30
tsconfig.json chore(api): compile TS into /dist (#49812 2023-03-28 19:42:20 +05:30

Working on the new api

Connecting to local database

The api uses the ORM Prisma and it needs the MongoDB instance to be a replica set.

Atlas

If you use MongoDB Atlas, the set is managed for you.

Local

The simplest way to run a replica set locally is to use the docker-compose file in /tools.

cd tools
docker compose up -d

Once that's running, update the connection string in the .env file to use port 27018.

# Database
MONGOHQ_URL=mongodb://127.0.0.1:27018/freecodecamp?directConnection=true

The new db will be empty, so you can run the seed script to populate it.

cd ../.. # back to the root of the repo
pnpm seed

Login in development/testing

During development and testing, the api exposes the endpoint GET auth/dev-callback. Calling this will log you in as the user with the email foo@bar.com by setting the session cookie for that user.