Skip to content

Commit 7ce7237

Browse files
committed
chore: added documentation for env vars and nginx configuration
1 parent ead2a91 commit 7ce7237

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

.env.example

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Port used to serve the frontend
1+
# Port used to serve the frontend (Only used in prod)
22
NGINX_PORT=80
33

44
# Credentials and hostname for the DB (Used by the docker compose)
@@ -29,12 +29,13 @@ REDIS_URL=redis://redis
2929
CLIST_USERNAME=
3030
CLIST_SECRET=
3131

32-
# Server port
32+
# Port on which the Express Server runs
3333
BACKEND_PORT=5000
34+
# Port on which the Vite frontend is served
3435
FRONTEND_PORT=5173
3536

36-
#Client facing api url (This is how your browser should reach the API)
37-
VITE_API_BASE_URL=http://localhost/api
37+
#Client facing api url (Can be specified wrt the root of your domain)
38+
VITE_API_BASE_URL=/api
3839

39-
# Used to control tanstack debug overlay (user development/production)
40+
# Used to control tanstack debug overlay (use development/staging/production)
4041
VITE_ENV=development

README.md

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ The official Competitive Coding website for BITS Pilani, Hyderabad Campus. Surge
6464
docker compose --profile prod down
6565
```
6666

67+
## Environment Variables
68+
Make a copy of the `.env.example` file, name it `.env` and include it in the root of your project directory. A list of reccomended defaults has been provided in `.env.example`. Here is an in depth explanation on a few environment variables which you might have to tweak based on your setup.
69+
70+
- `NGINX_PORT` - Used by nginx service running in the `frontend` service. This is only used in production and is the PORT which is exposed to the host and where the project is accessible in a production environment.
71+
72+
- `VITE_CLIENT_URL` - The URL via which your frontend is accessible. This is used to provide permanent links to rich preview images as well as auth redirects.
73+
74+
- `CALLBACK_URL` - This is the URL where the browser is redirected to, after the Google OAuth flow is completed successfully.
75+
76+
- `VITE_API_BASE_URL` - The path to your backend relative to the root of your domain. By default all requests to `/api` are rewritten to the backend via the `nginx.conf` file. This is also the default configured value in `.env.example`.
77+
78+
- `VITE_ENV` - Used to configure the environment where the project is running. Accepts values as `development`, `staging`, or `production`.
79+
80+
**NOTE: The cron jobs to refresh user information only run when `VITE_ENV` is set to `production`**
81+
82+
6783
## Migrations
6884
**Make sure you have the dev profile up and running before running migrations.**
6985

@@ -81,19 +97,30 @@ docker compose exec backend-dev npx drizzle-kit migrate
8197

8298
Runs migrations which haven't been applied yet. A list of migrations which have been applied is stored in a table in the database itself. Read more about this [here](https://github.com/jbranchaud/til/blob/master/drizzle/drizzle-tracks-migrations-in-a-log-table.md).
8399

84-
### Apply current schema to the database
85-
```bash
86-
docker compose exec backend-dev npx drizzle-kit push
87-
```
88-
This command **does not** generate migrations! Make sure to generate migrations for any major changes to ensure that the history of the database schema is always preserved.
89-
90100

91101
### Generate migrations from schema
92102
```bash
93103
docker compose exec backend-dev npx drizzle-kit generate
94104
```
95105
This compares the current state of the database with the schema and generates migrations.
96106

107+
## Nginx Setup
108+
The provided `nginx.dev.conf` should be configured to run with the default configs provided in `.env.example`. However for running in prod, the `nginx.prod.conf.example` file should be copied in the same directory and named `nginx.prod.conf`. After this, the ports in the config file should be configured accordingly.
109+
110+
### For dev
111+
The containers used for dev are:
112+
- `backend-dev`
113+
- `frontend-dev`
114+
- `nginx-dev`
115+
116+
Both `frontend-dev` and `backend-dev` are proxied through the `nginx` container. All requests to the `/api/*` route are forwarded to `backend-dev` and the rest are forwarded to `frontend-dev`.
117+
118+
### For prod
119+
The containers used for prod are:
120+
- `backend`
121+
- `frontend`
122+
123+
In the prod setup, the `frontend` service is a container running nginx. This container redirects all requests to `/api/*` routes to the `backend` service. All other requests are redirected internally to the compiled vite project. This nginx service is exposed to the host on the configured `NGINX_PORT` environment variable.
97124

98125
## Contribution
99126

0 commit comments

Comments
 (0)