Skip to content

Commit 6105aab

Browse files
authored
Adds support for both API URIs (#4)
Co-authored-by: Christopher Buecheler <chris@embeddable.com>
1 parent f73507e commit 6105aab

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

client/public/index.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,20 @@
2525
Learn how to configure a non-root public URL by running `npm run build`.
2626
-->
2727
<title>React App</title>
28+
<!--
29+
If you are on the EU server, please uncommented that tag and comment
30+
out the US tag.
31+
-->
2832
<script
2933
type="module"
30-
src="https://api.embeddable.com/js/v1/">
34+
src="https://api.us.embeddable.com/js/v1/">
3135
</script>
36+
<!--
37+
<script
38+
type="module"
39+
src="https://api.eu.embeddable.com/js/v1/">
40+
</script>
41+
-->
3242
</head>
3343
<body>
3444
<noscript>You need to enable JavaScript to run this app.</noscript>

server/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ const SECURITY_CONTEXT = {
99
userId: '9sZSJ9LHsiYXR0cmlidX'
1010
};
1111
const USER_KEY = 'some-user@domain.com';
12-
12+
const BASE_URL = 'https://api.us.embeddable.com'; // US
13+
// const BASE_URL = 'https://api.eu.embeddable.com'; // EU
1314

1415
const app = express();
1516

1617
// Have Node serve the files for our built React app
1718
app.use(express.static(path.resolve(__dirname, '../client/build')));
1819

1920
app.get('/embeddables', async (req, res) => {
20-
const response = await fetch(`https://api.embeddable.com/api/v1/embeddables`, {
21+
const response = await fetch(`${BASE_URL}/api/v1/embeddables`, {
2122
method: 'GET',
2223
headers: {
2324
'Content-Type': 'application/json',
@@ -33,7 +34,7 @@ app.get('/embeddables', async (req, res) => {
3334

3435
app.get('/token', async (req, res) => {
3536
console.log(req)
36-
const response = await fetch(`https://api.embeddable.com/api/v1/security-token`, {
37+
const response = await fetch(`${BASE_URL}/api/v1/security-token`, {
3738
method: 'POST',
3839
headers: {
3940
'Content-Type': 'application/json',

src/react-test.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
<head>
44
<title>Embedabble</title>
55
<meta charset="utf-8" />
6-
<script type="module" src="https://api.embeddable.com/js/v1/"></script>
6+
<!--
7+
If you are on the EU server, please uncomment that line and
8+
comment out the US line.
9+
-->
10+
<script type="module" src="https://api.us.embeddable.com/js/v1/"></script>
11+
<!-- <script type="module" src="https://api.eu.embeddable.com/js/v1/"></script> -->
712
<script
813
src="https://unpkg.com/react@18/umd/react.development.js"
914
crossorigin

src/test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ const SECURITY_CONTEXT = {
1010
userId: '9sZSJ9LHsiYXR0cmlidX'
1111
};
1212
const USER_KEY = 'some-user@domain.com';
13-
13+
const BASE_URL = 'https://api.us.embeddable.com'; // US
14+
// const BASE_URL = 'https://api.eu.embeddable.com'; // EU
1415

1516
async function handler(req, res) {
1617
console.log('Fetching token...')
1718

18-
const response = await fetch(`https://api.embeddable.com/api/v1/security-token`, {
19+
const response = await fetch(`${BASE_URL}/api/v1/security-token`, {
1920
method: 'POST',
2021
headers: {
2122
'Content-Type': 'application/json',
@@ -57,7 +58,7 @@ async function handler(req, res) {
5758
<meta charset="utf-8" />
5859
<script
5960
type="module"
60-
src="https://api.embeddable.com/js/v1/"
61+
src="${BASE_URL}/js/v1/"
6162
></script>
6263
</head>
6364
<body>

0 commit comments

Comments
 (0)