Skip to content

Commit 5a33dca

Browse files
committed
README
1 parent 4873c3f commit 5a33dca

4 files changed

Lines changed: 108 additions & 2 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ Note the "No active client found" message, telling us that no client application
3636

3737
### Start the local React application
3838

39+
> [!WARNING]
40+
> Local testing is not allowed when using the productive ShapeDiver platform.
41+
> However, you can use a service like https://ngrok.com/ to provide a public URL for your localhost.
42+
> Your public URL will need to be whitelisted by ShapeDiver. Write to us at contact@shapediver.com
43+
> and ask us about it.
44+
> As an alternative, you can test a deployed version of this example [here](https://appbuilder.shapediver.com/stargate/v1/main/development/).
45+
3946
As a prerequisite install [Node.js 20](https://nodejs.org/en/about/previous-releases) and [pnpm](https://pnpm.io/).
4047

4148
Run `pnpm i` to install the required dependencies.

deploy-test.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash
2+
MAIN_TARGET="main"
3+
4+
# Function to build and deploy a test page for the Stargate Web Client example
5+
# $1: prefix - the prefix for the deployment, "stargate/v1/$MAIN_TARGET"
6+
# $2: version - the version of the deployment (branch name or npm version)
7+
# $3: deploying_branch - 1 if we are deploying a branch, 0 if we are deploying a version
8+
build_and_deploy() {
9+
prefix=$1
10+
version=$2
11+
deploying_branch=$3
12+
13+
echo "Building Stargate Web Client example version $version with prefix $prefix"
14+
vite build --base=$prefix/$version/
15+
if [ $? -ne 0 ]; then
16+
echo "Build failed."
17+
exit 1
18+
fi
19+
20+
if [ -z "$APPBUILDER_BUCKET" ]; then
21+
echo "APPBUILDER_BUCKET environment variable is not set."
22+
exit 1
23+
fi
24+
25+
cachecontrol="public, max-age=31536000, immutable"
26+
# if we are deploying a branch, we need to change the cache control, compared to a version
27+
if [ $deploying_branch -eq 1 ]; then
28+
cachecontrol="public, max-age=0, s-maxage=86400"
29+
fi
30+
31+
echo "Deploying to version $version with prefix $prefix to bucket $APPBUILDER_BUCKET"
32+
33+
# depending on the prefix, we need to deploy to different locations
34+
if [ $prefix == "stargate/v1/$MAIN_TARGET" ]; then
35+
aws s3 sync ./dist s3://$APPBUILDER_BUCKET/appbuilder/$prefix/$version/ --region us-east-1 --cache-control "$cachecontrol"
36+
touch empty
37+
aws s3 cp empty s3://$APPBUILDER_BUCKET/appbuilder/$prefix/$version --region us-east-1 \
38+
--website-redirect https://appbuilder.shapediver.com/$prefix/$version/ --cache-control "$cachecontrol"
39+
aws s3 cp empty s3://$APPBUILDER_BUCKET/appbuilder/$prefix/.invalidate --region us-east-1 \
40+
--cache-control "$cachecontrol"
41+
rm empty
42+
else
43+
echo "Unsupported prefix for deployment."
44+
exit 1
45+
fi
46+
}
47+
48+
# load environment variables from .env file
49+
if [ -f .env ]; then
50+
export $(grep -v '^#' .env | sed 's/#.*//' | sed 's/^ *//;s/ *$//' | xargs)
51+
fi
52+
53+
# where should we deploy?
54+
prefix=$1
55+
if [ -z "$prefix" ]; then
56+
echo "Please specify a prefix."
57+
exit 1
58+
fi
59+
60+
# check for git changes
61+
if [[ -n $(git status --porcelain) ]]; then
62+
echo "There are uncommitted changes."
63+
exit 1
64+
fi
65+
66+
# Get the current branch
67+
branch=$(git rev-parse --abbrev-ref HEAD)
68+
69+
# npm version
70+
npm_version=$(node -p "require('./package.json').version")
71+
echo "Current npm version: $npm_version"
72+
73+
deploying_branch=1
74+
75+
# If the branch is "development", "staging" or starts with "task/", we use the branch name as the version
76+
if [ "$branch" == "development" ] || [ "$branch" == "staging" ]; then
77+
deploying_branch=1
78+
version=$branch
79+
80+
# And we create a new tag with the name "WordPressPlugin@branch"
81+
git tag -fa "StargateWebClient@$branch" -m "Release of branch $branch"
82+
git push origin "StargateWebClient@$branch" --force
83+
elif [[ $branch == task/* ]]; then
84+
deploying_branch=1
85+
# In this case we have to remove the "task/" prefix
86+
version=${branch#task/}
87+
else
88+
echo "Unsupported branch name."
89+
exit 1
90+
fi
91+
92+
build_and_deploy $prefix $version $deploying_branch

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"build": "tsc && vite build",
2121
"optimize": "tsc && vite optimize --force",
2222
"preview": "vite preview",
23+
"deploy-test": "./deploy-test.sh stargate/v1/main",
2324
"eslint": "eslint .",
2425
"prettier": "prettier --write ./src/ ./*.ts ./eslint.config.mjs ./vite.config.ts ./tsconfig.json ./package.json",
2526
"test": "jest"

src/hooks/useShapeDiverAuth.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ import {useCallback, useEffect, useState} from "react";
1010
const refreshTokenKey = "shapediver_refresh_token";
1111
const codeVerifierKey = "shapediver_code_verifier";
1212
const oauthStateKey = "shapediver_oauth_state";
13-
const authBaseUrl = "https://staging-wwwcdn.us-east-1.shapediver.com";
13+
// Note: Local testing is not allowed when using the productive ShapeDiver platform.
14+
// However, you can use a service like https://ngrok.com/ to provide a public URL for your localhost.
15+
// Your public URL will need to be whitelisted by ShapeDiver. Write to us at contact@shapediver.com
16+
const authBaseUrl =
17+
window.location.hostname === "localhost"
18+
? "https://staging-wwwcdn.us-east-1.shapediver.com"
19+
: "https://www.shapediver.com";
1420
const authEndPoint = `${authBaseUrl}/oauth/authorize`;
1521
const clientId = "A085FCC5-6EEB-46A6-A381-ADCEDB6E59D6"; // "660310c8-50f4-4f47-bd78-9c7ede8e659b";
1622

@@ -51,7 +57,7 @@ function clearBrowserStorage() {
5157

5258
/** Get the URL to which the ShapeDiver Platform should redirect back after authentication */
5359
function getRedirectUri() {
54-
return window.location.origin + "/";
60+
return window.location.origin + window.location.pathname;
5561
}
5662

5763
interface Props {

0 commit comments

Comments
 (0)