Skip to content

Commit 1664c27

Browse files
author
Joe Wegner
committed
Do local setup via .env instead of editing actual files
1 parent cf088f6 commit 1664c27

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
# misc
1515
.DS_Store
16+
.env
1617
.env.local
1718
.env.development.local
1819
.env.test.local
@@ -23,4 +24,4 @@ yarn-debug.log*
2324
yarn-error.log*
2425

2526
# Local Netlify folder
26-
.netlify
27+
.netlify

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ Please note this project is designed to work with rooms that have [privacy](http
2424
## Running locally
2525

2626
1. Install dependencies `npm i`
27-
2. Start dev server `npm run dev`
28-
3. Then open your browser and go to `http://localhost:3002`
29-
4. Add the Daily room URL you created to line 31 of `api.js`, and follow the comment's instructions.
27+
2. Copy `sample.env` to a new file called `.env`, and fill in the REACT_APP_ values
28+
3. Start dev server `npm run dev`
29+
4. If it didn't open automatically, open your browser and go to `http://localhost:3002`
3030

3131
OR...
3232

@@ -38,7 +38,7 @@ If you want access to the Daily REST API (using the proxy as specified in `netli
3838
[![Deploy with Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/daily-demos/call-object-react)
3939
2. Install the Netlify CLI `npm i -g netlify-cli`
4040
3. Login to your account `netlify login`
41-
4. Rename `sample.env` to `.env` and add your API key
41+
4. Copy `sample.env` to a new file called `.env`, and fill in the DAILY_API_KEY
4242
5. Start the dev server `netlify dev`
4343

4444
> Note: If the API proxy isn't working locally you may need to run `netlify build` first. This will put API key in the `netlify.toml` file, so make sure you don't commit this change.

netlify.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
[[redirects]]
2727
from = "/*"
2828
to = "/index.html"
29-
status = 200
29+
status = 200

sample.env

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
DAILY_API_KEY=REPLACE_WITH_YOUR_API_KEY
1+
# This needs to be filled in to run on Netlify. Ignore if you're running locally
2+
DAILY_API_KEY=REPLACE_WITH_YOUR_API_KEY
3+
4+
# These need to be filled in if you are running the app locally. Ignore for Netlify
5+
REACT_APP_DAILY_DOMAIN=REPLACE_WITH_YOUR_DOMAIN
6+
REACT_APP_DAILY_ROOM=REPLACE_WITH_YOUR_ROOM_NAME

src/api.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ const newRoomEndpoint =
99
* in README.md
1010
*
1111
* See https://docs.daily.co/reference#create-room for more information on how
12-
* to use the Daily REST API to create rooms and what options are available.
12+
* to use the Daily REST API to create rooms and what options are available.
1313
*/
1414
async function createRoom() {
15-
1615
const exp = Math.round(Date.now() / 1000) + 60 * 30;
1716
const options = {
1817
properties: {
@@ -23,12 +22,19 @@ async function createRoom() {
2322
method: "POST",
2423
body: JSON.stringify(options),
2524
mode: 'cors',
26-
}),
27-
room = await response.json();
28-
return room;
25+
})
26+
if (response.status === 200) {
27+
return await response.json();
28+
} else if (response.status === 404 &&
29+
process.env.REACT_APP_DAILY_DOMAIN &&
30+
process.env.REACT_APP_DAILY_ROOM) {
2931

30-
// Comment out the above and uncomment the below, using your own URL
31-
// return { url: "https://your-domain.daily.co/hello" };
32+
return {
33+
url: `https://${process.env.REACT_APP_DAILY_DOMAIN}.daily.co/${process.env.REACT_APP_DAILY_ROOM}`
34+
}
35+
} else {
36+
throw new Error("Unable to create a Daily room. Check out the README.md for setup instruction!")
37+
}
3238
}
3339

3440
export default { createRoom };

0 commit comments

Comments
 (0)