This is a Next.js project bootstrapped with create-next-app.
First, run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun devOpen http://localhost:3000 with your browser to see the result.
You can start editing the page by modifying app/page.tsx. The page auto-updates as you edit the file.
This project uses next/font to automatically optimize and load Inter, a custom Google Font.
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!
The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
Check out our Next.js deployment documentation for more details.
This project includes a Docker Compose configuration to run a 3-node MongoDB replica set locally.
- Docker and Docker Compose installed.
- Node.js and npm installed (for using
package.jsonscripts).
- Start the MongoDB replica set:
This command will start three MongoDB containers (
npm run mongo:start
mongodb1,mongodb2,mongodb3) and a setup container (mongo-setup) that initializes the replica setrs0. Themongo-setupcontainer will run the initialization script and then exit. The MongoDB containers will continue running in the background.
To connect to the MongoDB replica set from your host machine (e.g., for Prisma Studio, npm run update-schema, or your application running directly on the host), you need to make the replica set members' hostnames (mongo1, mongo2, mongo3) resolvable to your local machine. This is because the MongoDB instances, while accessible via localhost:<port>, will report their replica set peers using their internal Docker hostnames (e.g., mongo1:27017), which your host machine doesn't know by default.
-
Modify your
/etc/hostsfile: Add the following lines to your/etc/hostsfile (you'll typically need administrator/sudo privileges):127.0.0.1 mongo1 127.0.0.1 mongo2 127.0.0.1 mongo3On Windows, the hosts file is usually located at
C:\Windows\System32\drivers\etc\hosts. -
Use the following connection string: After modifying your
/etc/hostsfile, use this connection string to connect from your host application or MongoDB client:mongodb://mongo1:27017,mongo2:27018,mongo3:27019/YOUR_DB_NAME?replicaSet=rs0Replace
YOUR_DB_NAMEwith your actual database name (e.g.,contracts). Note the different ports formongo1(27017),mongo2(27018), andmongo3(27019), which correspond to the ports mapped indocker-compose.yml. -
Update your
.envfile: Ensure yourDATABASE_URLin your.envfile (or similar configuration) is updated to this new connection string if your application needs to connect from the host. For example:DATABASE_URL="mongodb://mongo1:27017,mongo2:27018,mongo3:27019/contracts?replicaSet=rs0"
- From the Host (after setup): Use the connection string mentioned in "Host Machine Setup for Connection". This is suitable for tools like MongoDB Compass,
mongoshrun from your host, or your application when run directly on the host. - From within Docker containers (not in
mongo-network): If you have other Docker containers that need to connect and are not part of themongo-network, they would typically usehost.docker.internal:<port>for each member if the Docker version supports it, or require more complex network configuration. However, for this project, applications are expected to run on the host or within themongo-network. - From within
mongo-network(e.g., themongo-setupservice): Services within the same Docker network (mongo-network) can use the Docker hostnames directly (e.g.,mongodb://mongo1:27017,mongo2:27017,mongo3:27017/YOUR_DB_NAME?replicaSet=rs0). Notice the internal port27017is used for all members in this case.
npm run mongo:stopThis command will stop and remove the MongoDB containers and network. The data volumes (mongo1-data, mongo2-data, mongo3-data) will persist unless manually removed.
- The replica set is named
rs0. - The
init-replica-set.shscript configures the replica set members to identify themselves using their Docker hostnames (e.g.,mongo1:27017). This is why the/etc/hostsmodification is necessary for host access. - Individual MongoDB instances are exposed on the host machine as follows:
mongo1(primary initially):localhost:27017(maps to container port 27017)mongo2:localhost:27018(maps to container port 27017)mongo3:localhost:27019(maps to container port 27017) While you can connect to an individual member usinglocalhost:<port>, this does not provide full replica set functionality from the host without the/etc/hostsmodification.