Skip to content

Commit 57ba568

Browse files
Added documentation for starting development
1 parent be92669 commit 57ba568

File tree

5 files changed

+121
-7
lines changed

5 files changed

+121
-7
lines changed

README.md

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Getting started with developing for the Critter Capture Club
2+
3+
Prerequisites:
4+
5+
- Clone the repo
6+
- Ensure you have `pnpm` installed
7+
- Run `pnpm install` to install the dependencies
8+
9+
To get started with development, you have a couple options.
10+
11+
## UI only development
12+
13+
If you're interested on working on the UI, you can use the production API by default.
14+
15+
Run `pnpm --filter=@critter/ui start` to start the development server and point your browser to http://localhost:5173. Make any changes you'd like and submit a PR for it!
16+
17+
## UI & API development
18+
19+
If you're interested in working on both the UI and API, there are a couple more steps to complete.
20+
21+
- Ensure you have `docker` installed and running on your machine
22+
- You will need to copy the `src/services/api/.env.example` file to `src/services/api/.env` and supply the correct environment variables.
23+
24+
### Variables you will need to change
25+
26+
- `TWITCH_CLIENT_ID`
27+
- `TWITCH_CLIENT_SECRET`
28+
- `TWITCH_USERNAME`
29+
30+
Go to the [Twitch Developer Dashboard](https://dev.twitch.tv/console) and create a new application to get your `TWITCH_CLIENT_ID` and `TWITCH_CLIENT_SECRET`. Ensure that you set the redirect URL to `http://localhost:35523/auth/redirect` & `http://localhost:35523/admin/redirect`.
31+
32+
You also need to specifiy the username of the bot you'd like to use in the `TWITCH_USERNAME` variable. For development, it makes sense to use your own.
33+
34+
- `STORAGE_ACCOUNT_NAME`
35+
- `STORAGE_ACCOUNT_KEY`
36+
- `CONTAINER_NAME`
37+
38+
Currently, we don't support the Azurite emulator for local development, so you'll need to have an Azure storage account and container that you can use.
39+
40+
### Variables you could change
41+
42+
- `JWT_SECRET`
43+
44+
This is the secret that the API uses to sign the JWTs. For local development, you can stick to the default value but know that it makes the token insecure.
45+
46+
- `COMMAND_PREFIX`
47+
48+
This is the prefix that the bot will respond to. If you're developing in a channel with other people/bots, it's a good idea to change this so you don't have commands that conflict with others.
49+
50+
- `CHANNELS_TO_LISTEN_TO`
51+
52+
This is an array of channels that the bot will join and listen to. Probably just stick to your own channel for local development.
53+
54+
### Variables you probably should keep the same
55+
56+
- `UI_URL`
57+
- `REDIS_HOST`
58+
- `REDIS_PORT`
59+
- `REDIS_PASSWORD`
60+
- `REDIS_SSL`
61+
- `POSTGRES_USER`
62+
- `POSTGRES_PASSWORD`
63+
- `POSTGRES_DB`
64+
- `POSTGRES_HOST`
65+
- `HOST`
66+
- `PORT`
67+
68+
These are all the default values that are used when the local docker compose file is ran. Unless you have a reason to change them, it's best to keep them the same.
69+
70+
### Running the services
71+
72+
In the root of the repo, run `docker compose up` to start the remaining services needed for the API to function.
73+
74+
- Edit the file found in `apps/ui/src/services/backstage/local.ts` and point the `apiBaseUrl` to the API URL you're running locally. (You can probably just uncomment the line.)
75+
76+
You can now make changes to both the UI and API and submit a PR for it!
77+
78+
- Run `pnpm --filter=@critter/api start` to start the API (you can use `pnpm --filter=@critter/api dev` to start the API in "watch" mode.)
79+
- Run `pnpm --filter=@critter/ui start` to start the UI
80+
81+
### Seeding the database
82+
83+
You will need to seed the database with the correct data.
84+
85+
The most important thing to to set a role for your account so you can access the UI. Create an entry in the `Roles` table, add your username and set yourself as an Admin. (This will be scripted soon.)
86+
87+
### Running the chat service
88+
89+
You will need to authenticate the bot in order for it to connect to Twitch. When running both the UI & the API, go to http://localhost:5173/status and authenticate the bot with the correct credentials.
+3-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import { DeepPartial } from 'ts-essentials';
22
import { Config } from './config';
33

4-
export const url = 'https://ccprodweb832aa1fe.z5.web.core.windows.net//backstage.json';
4+
export const url = 'https://ccprodweb832aa1fe.z5.web.core.windows.net/backstage.json';
55

66
export const config: DeepPartial<Config> = {
77
variables: {
8-
apiBaseUrl: 'http://localhost:35523',
9-
imageResizeCDNUrl: 'https://crittercapture.club/cdn-cgi/image',
10-
11-
docsUrl: 'https://github.com/changesbyjames/crittercapture/tree/main/docs'
8+
// apiBaseUrl: 'http://localhost:35523'
9+
// imageResizeCDNUrl: 'https://crittercapture.club/cdn-cgi/image',
1210
},
1311
flags: {}
1412
};

services/api/.env.example

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
TWITCH_CLIENT_ID=
2+
TWITCH_CLIENT_SECRET=
3+
TWITCH_USERNAME=
4+
5+
REDIS_HOST=localhost
6+
REDIS_PORT=6379
7+
8+
HOST=localhost
9+
PORT=35523
10+
11+
POSTGRES_USER=myuser
12+
POSTGRES_PASSWORD=mypassword
13+
POSTGRES_DB=db01
14+
POSTGRES_HOST=localhost
15+
16+
UI_URL=http://localhost:5173
17+
18+
JWT_SECRET=bed840003446895cfee9182afad1c9adace070b0b54cdfdc640d61b981b5a5aeb3af9519785d5935b8de0f25469b782701b2276a22df329a971c3065bd59a565
19+
COMMAND_PREFIX=$
20+
CHANNELS_TO_LISTEN_TO=
21+
22+
STORAGE_ACCOUNT_NAME=
23+
STORAGE_ACCOUNT_KEY=
24+
CONTAINER_NAME=

services/api/src/services/chat/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const handler: Record<string, (chat: ChatClient, channel: string, user: string,
2626

2727
export const status: Status = {
2828
status: 'pending',
29-
channels: ['strangecyan', 'alveusgg'],
29+
channels: [],
3030
commands: Object.keys(handler)
3131
};
3232

@@ -47,7 +47,8 @@ export const start = async () => {
4747
auth.onRefresh((_, token) => saveToken(token));
4848
await auth.addUserForToken(token, ['chat']);
4949

50-
const chat = new ChatClient({ authProvider: auth, channels: status.channels });
50+
const chat = new ChatClient({ authProvider: auth, channels: env.variables.CHANNELS_TO_LISTEN_TO });
51+
status.channels = env.variables.CHANNELS_TO_LISTEN_TO;
5152
chat.onConnect(() => (status.status = 'online'));
5253

5354
chat.onDisconnect(() => (status.status = 'offline'));

services/api/src/utils/env/config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export const config = z.object({
3030
STORAGE_ACCOUNT_KEY: z.string(),
3131
CONTAINER_NAME: z.string(),
3232

33+
CHANNELS_TO_LISTEN_TO: z.string().transform(value => value.split(',')),
34+
3335
COMMAND_PREFIX: z.string().default('!'),
3436
JWT_SECRET: z.string().transform(value => Buffer.from(value, 'hex'))
3537
});

0 commit comments

Comments
 (0)