Skip to content

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
brentvollebregt committed Oct 4, 2024
1 parent ad3f90b commit 3d57d78
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,20 @@

1. Clone the repo and cd into the project.
2. Install dependencies by executing `npm install`.
3. Setup environment variables. This can be done two ways:
3. Setup environment variables. Either:
- Set the environment variables in the current terminal session
- Copy the .env.example files in the server and client packages and populate them:
- Examples are at: `packages/server/.env.example` and `packages/client/.env.example`
- Copy these using `cp .env.example .env` and populate them both.
- `cp packages/server/.env.example packages/server/.env`
- `cp packages/client/.env.example packages/client/.env`
4. Build dependencies using `npm run build`.
5. Execute `npm start` to start the server.

> You may need to set `CI=false` when building to ignore the warnings from the frontend project.
The environment variables that can be used are (can also be found in .env.example files):

- `VITE_API_ROOT` (optional): The route that the client requests. Not setting this will default to `window.location.origin`.
- `SERVER_ALLOWED_ORIGINS` (optional): The origins that are served by the server. Not setting this is the equivalent of setting CORS to \*.

### 🧪 Development Setup

When running the client in development mode using `npm run client:dev`, the client will use the `VITE_API_ROOT` environment variable value to decide where to send requests. If this is not provided, the current hosted URL will be used.
To setup hot reloading on the backend and frontend:

`npm run server:dev` can also be used for development of the server; this allows for hot-reloading. Running the client using `npm run client:dev` and setting `VITE_API_ROOT` to where the server is running will allow for a development setup with hot-reloading.
- Run the backend using `npm run server:dev`
- Run the frontend using `npm run client:dev`

> `launch.json` also offers the ability to connect and debug the the server when running `npm run client:dev`.
Expand Down
8 changes: 7 additions & 1 deletion packages/client/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# The API root (where the server package is being hosted)
VITE_API_ROOT=http://localhost:5000
VITE_GOOGLE_ANALYTICS_TRACKING_ID=G-XXXXXXXXX

# Google Analytics tracking code (can leave as this)
VITE_GOOGLE_ANALYTICS_TRACKING_ID=G-XXXXXXXXX

# A message to show when the API is unreacable (optional)
# VITE_API_UNREACHABLE_ERROR_MESSAGE= # Disabled by default
2 changes: 1 addition & 1 deletion packages/client/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {
api: {
root: import.meta.env.VITE_API_ROOT ? import.meta.env.VITE_API_ROOT : window.location.origin,
root: import.meta.env.VITE_API_ROOT,
unreachableErrorMessage:
import.meta.env.VITE_API_UNREACHABLE_ERROR_MESSAGE ?? "Unable to communicate with server"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// <reference types="vite-plugin-svgr/client" />

interface ImportMetaEnv {
readonly VITE_API_ROOT?: string;
readonly VITE_API_ROOT: string;
readonly VITE_GOOGLE_ANALYTICS_TRACKING_ID?: string;
readonly VITE_API_UNREACHABLE_ERROR_MESSAGE?: string;
}
Expand Down
1 change: 1 addition & 0 deletions packages/server/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# The origins allowed to make calls to the server (where the frontend is hosted). Can be multiple domains separated by commas.
SERVER_ALLOWED_ORIGINS=http://localhost:3000

0 comments on commit 3d57d78

Please sign in to comment.