Skip to content

Commit 633ccdc

Browse files
VIDCS-3721: improvements-documentation-video-example
Removed the default * (catch-all) route for unfound API endpoints. This behavior was not API-friendly and caused confusion. Fixed project scripts: some were intended to run both the backend and frontend simultaneously, but Bash is not concurrent by default. We now use concurrently (via npm) to achieve the desired result. Added a script for debugging the backend project. Updated the README to make the tutorial more detailed and beginner-friendly. Readme now includes a clearer explanation of where and how to retrieve the necessary Vonage credentials. Added steps for testing the app with multiple devices on a local network.
1 parent 4d9a3a3 commit 633ccdc

12 files changed

+148
-52
lines changed

README.md

Lines changed: 79 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -114,49 +114,105 @@ The Vonage Video API Reference App for React is currently supported on the lates
114114

115115
## Running Locally
116116

117-
### Config
117+
### 1. Ensure You Have a Vonage Account
118118

119-
In project directory, create the environment variables for the project.
119+
To get started, make sure you have a Vonage account. You can create one at the [Vonage API Dashboard](https://dashboard.vonage.com/applications). The sign-up process is straightforward.
120120

121-
```console
122-
cp backend/.env.example backend/.env
123-
```
124-
[Click here](backend/.env.example) to learn more about config variables used in the backend.
121+
### 2. Create an Application in the Dashboard
125122

126-
Add your Vonage Video API credentials to the newly created .env file.
123+
Once logged in, navigate to the [Applications page](https://dashboard.vonage.com/applications) via the main dashboard menu:
127124

128-
```console
129-
cp frontend/.env.example frontend/.env
125+
<details open>
126+
<summary>Applications dashboard view</summary>
127+
<img src="./docs/assets/readme/1-dashboard-applications.png" alt="Applications dashboard" style="max-width: 100%; height: auto;" />
128+
</details>
129+
130+
If you don’t already have an application, create a new one:
131+
132+
<details open>
133+
<summary>Create new app</summary>
134+
<img src="./docs/assets/readme/2-create-app.png" alt="Create app button" style="max-width: 100%; height: auto;" />
135+
</details>
136+
137+
During the setup process, make sure to:
138+
139+
- Provide a name for your application.
140+
- Generate and download the public and private keys.
141+
- Enable **Video** capabilities.
142+
143+
Refer to the following image for visual guidance:
144+
145+
<details open>
146+
<summary>Configuring a new app</summary>
147+
<img src="./docs/assets/readme/3-create-app-form.png" alt="Create app form" style="max-width: 100%; height: auto;" />
148+
</details>
149+
150+
### 3. Environment Variable
151+
152+
In the root project directory, create the environment files by running:
153+
154+
``` bash
155+
cp backend/.env.example backend/.env && cp frontend/.env.example frontend/.env
130156
```
131-
[Click here](frontend/.env.example) to learn more about config variables used in the frontend.
132157

133-
### Running the project
158+
Then, open **backend/.env** and fill in the required configuration:
134159

135-
#### Installing dependencies
160+
- **VONAGE_APP_ID** – This is the ID of your Vonage application. You can find it on the [Applications page](https://dashboard.vonage.com/applications).
161+
- **VONAGE_PRIVATE_KEY** – If you've already generated a private key, use that. Otherwise, use the key you downloaded when creating the app.
136162

137-
```console
163+
### 4. Running the Project
164+
165+
#### Install Dependencies
166+
167+
``` bash
138168
yarn
139169
```
140-
This command installs all appropriate dependencies for the project. If you would like more information on the packages we use, please refer to the [Dependencies](./docs/DEPENDENCIES.md) document.
141170

142-
#### Dev mode
171+
This command installs all necessary dependencies. For details about the packages used, refer to [Dependencies](./docs/DEPENDENCIES.md).
143172

144-
```console
173+
#### Start in Development Mode
174+
175+
``` bash
145176
yarn dev
146177
```
147178

148-
This command builds and watches both the backend server (:3345) and frontend vite dev server (:5173)
149-
You should now see the app running at [http://localhost:5173/](http://localhost:5173/)
179+
This starts both the backend server (port **3345**) and the frontend Vite dev server (port **5173**). You can now access the app at [http://localhost:5173](http://localhost:5173).
150180

151-
#### Production mode
181+
### 5. Testing on Multiple Devices
152182

153-
This command builds a production bundle of the app frontend and `cp`s it to the backend to be served by the express server.
183+
To test the video API across multiple devices on your local network, you can use **ngrok** to expose your frontend publicly.
154184

155-
```console
156-
yarn start
185+
#### Steps:
186+
187+
1. Create an account at [ngrok](https://dashboard.ngrok.com/signup) if you haven’t already (The free tier allows you to have one public tunnel).
188+
189+
2. Follow the [Setup and Installation instructions](https://dashboard.ngrok.com/get-started/setup/) for your operating system to install and configure ngrok.
190+
191+
3. Create a secure tunnel to your frontend using:
192+
193+
``` bash
194+
yarn forward:frontend
157195
```
158196

159-
The app and API are both served on [http://localhost:3345/](http://localhost:3345/)
197+
This command creates a publicly accessible HTTPS URL for your frontend. It will appear in your terminal, similar to the image below:
198+
199+
<details open>
200+
<summary>ngrok output example</summary>
201+
<img src="./docs/assets/readme/4-forwarding front-end.png" alt="ngrok tunnel example" style="max-width: 100%; height: auto;" />
202+
</details>
203+
204+
4. Copy the domain from the output and update your **frontend/.env** file:
205+
206+
``` ini
207+
# example
208+
VITE_NGROK_DOMAIN=332a-45-137-35-107.ngrok-free.app
209+
```
210+
211+
**Note:** ngrok assigns a temporary domain. You’ll need to update your environment variable each time the domain changes.
212+
213+
5. Open the provided **Forwarding** URL in your browser. This exposes your Vite app publicly. However, keep in mind that the backend server is still local, so the devices accessing the app must be on the same local network.
214+
215+
Enjoy testing!
160216

161217
## Deployment to Vonage Cloud Runtime
162218

backend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
"main": "index.js",
66
"type": "module",
77
"scripts": {
8-
"dev": "tsx watch --ignore ./tests/**/*.test.ts index.ts",
8+
"dev": "tsx watch index.ts",
99
"start": "node --import tsx index.ts",
10+
"debug": "node --inspect --watch --import tsx index.ts",
1011
"test": "NODE_OPTIONS=\"--experimental-vm-modules\" jest --maxWorkers=1 --coverage",
1112
"test:watch": "yarn test --watch",
1213
"ts-check": "tsc -p tsconfig.json"

backend/server.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import express, { Express, Request, Response } from 'express';
1+
import express, { Express } from 'express';
22
import path from 'path';
33
import bodyParser from 'body-parser';
44
import { fileURLToPath } from 'url';
@@ -27,10 +27,6 @@ app.use((_req, res, next) => {
2727

2828
app.use(express.static(path.join(dirName, './dist')));
2929

30-
app.get('/*', (_req: Request, res: Response) => {
31-
res.sendFile(path.join(dirName, 'dist', 'index.html'));
32-
});
33-
3430
const startServer: () => Promise<Server> = () => {
3531
return new Promise((res) => {
3632
const server: Server = app.listen(port, () => {
Loading

docs/assets/readme/2-create-app.png

174 KB
Loading
159 KB
Loading
38.6 KB
Loading

frontend/.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ VITE_ENABLE_REPORT_ISSUE=false
99
# This is meant for development only.
1010
# Note: this only works when opening a room url directly, not when navigating via the landing page.
1111
VITE_BYPASS_WAITING_ROOM=false
12+
13+
# For testing with multiple devices, you can use ngrok to expose your vite server to the internet.
14+
# your can see more information on how this works at https://ngrok.com/docs/
15+
VITE_NGROK_DOMAIN=332a-45-137-35-107.ngrok-free.app

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"scripts": {
88
"build": "vite build && yarn cp-build",
99
"cp-build": "mkdir -p ../backend/dist && cp -r dist ../backend",
10-
"dev": "vite",
10+
"dev": "vite --host",
1111
"docs": "typedoc",
1212
"docs:watch": "typedoc --watch",
1313
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",

frontend/vite.config.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// <reference types="vitest" />
2-
import { defineConfig, mergeConfig } from 'vite';
2+
import { defineConfig, loadEnv, mergeConfig } from 'vite';
33
import type { UserConfig as VitestUserConfigInterface } from 'vitest/config';
44
import { defineConfig as defineVitestConfig } from 'vitest/config';
55
import react from '@vitejs/plugin-react';
@@ -26,17 +26,23 @@ const vitestConfig: VitestUserConfigInterface = defineVitestConfig({
2626
});
2727

2828
// https://vitejs.dev/config/
29-
const viteConfig = defineConfig({
30-
optimizeDeps: {
31-
include: ['@emotion/react', '@emotion/styled', '@mui/material/Tooltip'],
32-
},
33-
plugins: [
34-
react(),
35-
replace({
36-
'process.env.CI': process.env.CI,
37-
preventAssignment: true,
38-
}),
39-
],
40-
});
29+
export default defineConfig(({ mode }) => {
30+
const env = loadEnv(mode, process.cwd());
4131

42-
export default mergeConfig(vitestConfig, viteConfig);
32+
return mergeConfig(vitestConfig, {
33+
server: {
34+
host: true,
35+
allowedHosts: ['*', env.VITE_NGROK_DOMAIN],
36+
},
37+
optimizeDeps: {
38+
include: ['@emotion/react', '@emotion/styled', '@mui/material/Tooltip'],
39+
},
40+
plugins: [
41+
react(),
42+
replace({
43+
'process.env.CI': process.env.CI,
44+
preventAssignment: true,
45+
}),
46+
],
47+
});
48+
});

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@
1515
"scripts": {
1616
"build": "yarn workspace frontend build",
1717
"deploy-vcr": "vcr deploy",
18-
"dev": "yarn && yarn workspace frontend dev & yarn workspace backend dev",
18+
"dev": "concurrently 'yarn workspace frontend dev' 'yarn workspace backend dev'",
1919
"docs": "yarn workspace frontend docs",
2020
"docs:watch": "yarn workspace frontend docs:watch",
2121
"lint": "ESLINT_USE_FLAT_CONFIG=false yarn eslint . --ext .ts,.tsx",
2222
"lint:filenames": "./scripts/lintFileNames.sh",
2323
"lint:fix": "yarn prettier --write . && yarn lint --fix",
2424
"postinstall": "husky",
2525
"run-server": "yarn workspace backend start",
26-
"start": "yarn workspace frontend build && yarn workspace backend start",
26+
"start": "yarn workspace backend start",
2727
"start:backend": "yarn workspace backend dev",
28+
"debug:backend": "yarn workspace backend debug",
2829
"start:frontend": "yarn workspace frontend dev",
30+
"forward:frontend": "npx ngrok http 5173",
2931
"test": "yarn test:backend && yarn test:frontend",
3032
"test:backend": "yarn workspace backend test",
3133
"test:backend:watch": "yarn workspace backend test:watch",
@@ -68,6 +70,7 @@
6870
"husky": "^9.0.11",
6971
"license-checker": "^25.0.1",
7072
"lint-staged": "^15.2.2",
73+
"concurrently": "^9.1.2",
7174
"prettier": "^3.2.5",
7275
"typescript": "^5.8.3"
7376
},

yarn.lock

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3357,7 +3357,7 @@ chalk@^3.0.0:
33573357
ansi-styles "^4.1.0"
33583358
supports-color "^7.1.0"
33593359

3360-
chalk@^4.0.0, chalk@^4.1.0:
3360+
chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.2:
33613361
version "4.1.2"
33623362
resolved "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz"
33633363
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
@@ -3548,6 +3548,19 @@ [email protected]:
35483548
resolved "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz"
35493549
integrity sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==
35503550

3551+
concurrently@^9.1.2:
3552+
version "9.1.2"
3553+
resolved "https://registry.yarnpkg.com/concurrently/-/concurrently-9.1.2.tgz#22d9109296961eaee773e12bfb1ce9a66bc9836c"
3554+
integrity sha512-H9MWcoPsYddwbOGM6difjVwVZHl63nwMEwDJG/L7VGtuaJhb12h2caPG2tVPWs7emuYix252iGfqOyrz1GczTQ==
3555+
dependencies:
3556+
chalk "^4.1.2"
3557+
lodash "^4.17.21"
3558+
rxjs "^7.8.1"
3559+
shell-quote "^1.8.1"
3560+
supports-color "^8.1.1"
3561+
tree-kill "^1.2.2"
3562+
yargs "^17.7.2"
3563+
35513564
confbox@^0.1.7:
35523565
version "0.1.7"
35533566
resolved "https://registry.npmjs.org/confbox/-/confbox-0.1.7.tgz"
@@ -7701,6 +7714,13 @@ run-parallel@^1.1.9:
77017714
dependencies:
77027715
queue-microtask "^1.2.2"
77037716

7717+
rxjs@^7.8.1:
7718+
version "7.8.2"
7719+
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.8.2.tgz#955bc473ed8af11a002a2be52071bf475638607b"
7720+
integrity sha512-dhKf903U/PQZY6boNNtAGdWbG85WAbjT/1xYoZIC7FAY0yWapOBQVsVrDl58W86//e1VpMNBtRV4MaXfdMySFA==
7721+
dependencies:
7722+
tslib "^2.1.0"
7723+
77047724
safe-array-concat@^1.1.2:
77057725
version "1.1.2"
77067726
resolved "https://registry.npmjs.org/safe-array-concat/-/safe-array-concat-1.1.2.tgz"
@@ -7842,6 +7862,11 @@ shebang-regex@^3.0.0:
78427862
resolved "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz"
78437863
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
78447864

7865+
shell-quote@^1.8.1:
7866+
version "1.8.2"
7867+
resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.8.2.tgz#d2d83e057959d53ec261311e9e9b8f51dcb2934a"
7868+
integrity sha512-AzqKpGKjrj7EM6rKVQEPpB288oCfnrEIuyoT9cyF4nmGa7V8Zk6f7RRqYisX8X9m+Q7bd632aZW4ky7EhbQztA==
7869+
78457870
shiki@^1.16.2:
78467871
version "1.22.2"
78477872
resolved "https://registry.yarnpkg.com/shiki/-/shiki-1.22.2.tgz#ed109a3d0850504ad5a1edf8496470a2121c5b7b"
@@ -8271,9 +8296,9 @@ supports-color@^7.1.0:
82718296
dependencies:
82728297
has-flag "^4.0.0"
82738298

8274-
supports-color@^8.0.0:
8299+
supports-color@^8.0.0, supports-color@^8.1.1:
82758300
version "8.1.1"
8276-
resolved "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz"
8301+
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-8.1.1.tgz#cd6fc17e28500cff56c1b86c0a7fd4a54a73005c"
82778302
integrity sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==
82788303
dependencies:
82798304
has-flag "^4.0.0"
@@ -8424,6 +8449,11 @@ tr46@~0.0.3:
84248449
resolved "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz"
84258450
integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==
84268451

8452+
tree-kill@^1.2.2:
8453+
version "1.2.2"
8454+
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.2.tgz#4ca09a9092c88b73a7cdc5e8a01b507b0790a0cc"
8455+
integrity sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==
8456+
84278457
treeify@^1.1.0:
84288458
version "1.1.0"
84298459
resolved "https://registry.yarnpkg.com/treeify/-/treeify-1.1.0.tgz#4e31c6a463accd0943879f30667c4fdaff411bb8"
@@ -8473,7 +8503,7 @@ tsconfig-paths@^3.15.0:
84738503
minimist "^1.2.6"
84748504
strip-bom "^3.0.0"
84758505

8476-
tslib@^2.3.0:
8506+
tslib@^2.1.0, tslib@^2.3.0:
84778507
version "2.8.1"
84788508
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.1.tgz#612efe4ed235d567e8aba5f2a5fab70280ade83f"
84798509
integrity sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==
@@ -9036,9 +9066,9 @@ yargs-parser@^21.0.1, yargs-parser@^21.1.1:
90369066
resolved "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz"
90379067
integrity sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==
90389068

9039-
yargs@^17.3.1:
9069+
yargs@^17.3.1, yargs@^17.7.2:
90409070
version "17.7.2"
9041-
resolved "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz"
9071+
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.7.2.tgz#991df39aca675a192b816e1e0363f9d75d2aa269"
90429072
integrity sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==
90439073
dependencies:
90449074
cliui "^8.0.1"

0 commit comments

Comments
 (0)