Skip to content

Commit

Permalink
Merge pull request #63 from Avelous/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
Avelous authored Jul 26, 2024
2 parents dd06bdb + 8c5daac commit df615ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,30 @@ cd private-key-dice
```

2. Install Dependencies

Install the necessary dependencies by running:

```
yarn install
```

3. Configure Environment Variables(optional)

Create a `.env` file in the directory `packages/backend` and add your MongoDB connection string and Ably API key:

```env
PORT=6001
MONGO_URL=your_mongo_connection_string
ABLY_API_KEY=your_ably_api_key
```
Alternatively, you can stick with values of backend.config.ts for testing

Alternatively, you can stick with values of `backend.config.ts` for testing

- Get a `mongo_url` by signing up at [MongoDB](https://www.mongodb.com/) and creating an cluster. [Learn More](https://www.mongodb.com/docs/drivers/node/v3.6/fundamentals/connection/connect/)
- Get an `ablyApiKey` by signing up at [Ably](https://ably.com/) and creating an application. [Learn More](https://ably.com/docs/connect)

4. Run the Server

Start the server using the following command:

```
Expand All @@ -86,7 +90,8 @@ The complete setup is in `packages/backend/index.ts`.

### MongoDB Setup

The server uses Mongoose to connect to MongoDB. Ensure your MongoDB URL is correctly set in the .env file or backend.config.ts. The connection logic includes an automatic retry mechanism in case the initial connection fails.
The server uses [Mongoose](https://mongoosejs.com/docs/) to connect to MongoDB. Ensure your MongoDB URL is correctly set in the `.env` file or `backend.config.ts`. The connection logic includes an automatic retry mechanism in case the initial connection fails.


```typescript
const connectWithRetry = async () => {
Expand All @@ -112,7 +117,8 @@ connectWithRetry();
Ably is configured to publish real-time updates to the `gameUpdate` channel whenever a game state is updated. This allows clients to receive updates instantaneously.

### Backend Ably Setup
The Ably client is initialized with your API key:
The Ably client is initialized with the API key at `packages/backend/index.ts`:


```typescript
export const ably = new Ably.Realtime({ key: process.env.ABLY_API_KEY || backendConfig.ablyApi });
Expand Down Expand Up @@ -152,8 +158,6 @@ useEffect(() => {
}, [game, ablyApiKey]);
```

Ensure your frontend application includes the Ably JavaScript SDK and correctly initializes the ablyApiKey.

### Additional Information

- Controllers: Game logic for admin and player operations.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ yarn backend

This command starts a local backend on port `6001` and can be used for testing and development. You can customize the configuration in `backend.config.ts` and add your very own `.env` file following the `packages/backend/.env.example`.

3. On a third terminal, start your NextJS app:
3. On a second terminal, start your NextJS app:

```
yarn start
Expand Down

0 comments on commit df615ca

Please sign in to comment.