Skip to content

Commit 317230d

Browse files
committed
Removes runtime env usage for build-time variables
Simplifies environment handling by adopting build-time variables, aligning with Azure deployments Removes the need for runtime script usage Adds example files demonstrating custom test flows
1 parent 5517cff commit 317230d

File tree

6 files changed

+512
-33
lines changed

6 files changed

+512
-33
lines changed

editor/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,22 @@ ARG VITE_APP_VERSION=1.0.0
77
ARG VITE_APP_BUILD_TIME
88
ARG VITE_APP_COMMIT_SHA
99

10+
# Build arguments for Azure App Service environment variables (these come from Azure during build)
11+
ARG VITE_BACKEND_BASE_URL
12+
ARG VITE_LOGIN_BASE_URL
13+
ARG VITE_OAUTH_WEB_CLIENT_ID
14+
ARG VITE_OAUTH_WEB_CLIENT_SECRET
15+
ARG VITE_NODE_ENV
16+
1017
# Set environment variables for the build (Vite requires VITE_ prefix)
1118
ENV VITE_APP_VERSION=$VITE_APP_VERSION
1219
ENV VITE_APP_BUILD_TIME=$VITE_APP_BUILD_TIME
1320
ENV VITE_APP_COMMIT_SHA=$VITE_APP_COMMIT_SHA
21+
ENV VITE_BACKEND_BASE_URL=$VITE_BACKEND_BASE_URL
22+
ENV VITE_LOGIN_BASE_URL=$VITE_LOGIN_BASE_URL
23+
ENV VITE_OAUTH_WEB_CLIENT_ID=$VITE_OAUTH_WEB_CLIENT_ID
24+
ENV VITE_OAUTH_WEB_CLIENT_SECRET=$VITE_OAUTH_WEB_CLIENT_SECRET
25+
ENV VITE_NODE_ENV=$VITE_NODE_ENV
1426

1527
# Copy package files first for better Docker layer caching
1628
COPY package.json package-lock.json ./

editor/index.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
<title>TrackMan Script Editor</title>
77
<link rel="icon" type="image/x-icon" href="https://golf-portal-dev.trackmangolfdev.com/favicon.ico" />
88
<link rel="stylesheet" href="/src/index.css" />
9-
<!-- Runtime environment configuration -->
10-
<script src="/env-config.js"></script>
119
</head>
1210
<body>
1311
<div id="root"></div>

editor/src/lib/auth-service.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,6 @@ class AuthService {
219219
const { buildAuthorizationUrl, generateCodeVerifier, generateState } = await import('./oauth2-utils');
220220
const { ENV_URLS, OAUTH_CONFIG } = await import('./env');
221221

222-
223-
224222
// Check for required configuration
225223
if (!OAUTH_CONFIG.webClientId) {
226224
console.error('❌ Missing OAuth client ID');

editor/src/lib/env.ts

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,19 @@ function stripTrailingSlash(url: string): string {
2020
}
2121

2222
const backendBase = (() => {
23-
// Try runtime environment first (for Azure App Service)
24-
const runtimeBase = (window as any)?.env?.VITE_BACKEND_BASE_URL;
25-
if (runtimeBase && runtimeBase !== '__VITE_BACKEND_BASE_URL__') {
26-
return stripTrailingSlash(runtimeBase);
27-
}
28-
29-
// Fall back to build-time environment
3023
const base = import.meta.env.VITE_BACKEND_BASE_URL?.trim();
3124
if (base) return stripTrailingSlash(base);
3225

3326
// Legacy fallback
3427
const legacyGraphql = import.meta.env.VITE_GRAPHQL_URL?.trim();
3528
if (legacyGraphql) {
3629
console.warn('[env] Using legacy VITE_GRAPHQL_URL as backend base fallback');
37-
// Remove /graphql suffix if present
3830
return stripTrailingSlash(legacyGraphql.replace(/\/graphql$/, ''));
3931
}
4032
return '';
4133
})();
4234

4335
const loginBase = (() => {
44-
// Try runtime environment first (for Azure App Service)
45-
const runtimeBase = (window as any)?.env?.VITE_LOGIN_BASE_URL;
46-
if (runtimeBase && runtimeBase !== '__VITE_LOGIN_BASE_URL__') {
47-
return stripTrailingSlash(runtimeBase);
48-
}
49-
50-
// Fall back to build-time environment
5136
const base = import.meta.env.VITE_LOGIN_BASE_URL?.trim();
5237
if (base) return stripTrailingSlash(base);
5338

@@ -69,25 +54,17 @@ export const ENV_URLS = {
6954
};
7055

7156
// OAuth Web Client Configuration (for authorization code flow)
72-
// Function to get OAuth client ID with proper runtime support
57+
// Function to get OAuth client ID - simplified approach
7358
function getOAuthClientId(): string {
74-
// Try runtime environment first (for Azure App Service)
75-
const runtimeClientId = (window as any)?.env?.VITE_OAUTH_WEB_CLIENT_ID;
76-
if (runtimeClientId && runtimeClientId !== '__VITE_OAUTH_WEB_CLIENT_ID__') {
77-
return runtimeClientId;
78-
}
79-
// Fallback to build-time environment variable
59+
// Use build-time environment variable directly
60+
// This will be set during the Docker build process in Azure
8061
return import.meta.env.VITE_OAUTH_WEB_CLIENT_ID || '';
8162
}
8263

83-
// Function to get OAuth client secret with proper runtime support
64+
// Function to get OAuth client secret - simplified approach
8465
function getOAuthClientSecret(): string {
85-
// Try runtime environment first (for Azure App Service)
86-
const runtimeClientSecret = (window as any)?.env?.VITE_OAUTH_WEB_CLIENT_SECRET;
87-
if (runtimeClientSecret && runtimeClientSecret !== '__VITE_OAUTH_WEB_CLIENT_SECRET__') {
88-
return runtimeClientSecret;
89-
}
90-
// Fallback to build-time environment variable
66+
// Use build-time environment variable directly
67+
// This will be set during the Docker build process in Azure
9168
return import.meta.env.VITE_OAUTH_WEB_CLIENT_SECRET || '';
9269
}
9370

examples/custom_test_sample.json

Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
{
2+
"id": "sample-custom-test",
3+
4+
"activities": [
5+
{
6+
"nodeType": "PerformanceCenterScriptedActivity",
7+
"id": "custom-test-sample",
8+
"introMessage": {
9+
"header": "CUSTOM TEST",
10+
"description": "You will be hitting shots with different clubs in varied scenarios",
11+
"seconds": 6
12+
},
13+
"endMessage": {
14+
"header": "TEST ENDED",
15+
"description": "",
16+
"seconds": 6
17+
},
18+
"steps": [
19+
{
20+
"nodeType": "PerformanceCenterScriptedStep",
21+
"id": "task-1-sample-id",
22+
"introMessage": {
23+
"header": "Shot 1",
24+
"description": "Hit your driver off the tee",
25+
"seconds": 5
26+
},
27+
"successMessage": {
28+
"header": "Success!",
29+
"description": "",
30+
"seconds": 3
31+
},
32+
"failMessage": {
33+
"header": "Failed",
34+
"description": "",
35+
"seconds": 3
36+
},
37+
"logic": {
38+
"nodeType": "PerformanceCenterScriptedLogic",
39+
"setup": {
40+
"nodeType": "PerformanceCenterTeeShotsScriptedSetup",
41+
"hole": 2,
42+
"playerCategory": "Handicap",
43+
"hcp": 15,
44+
"gender": "Male",
45+
"courseDistance": 5000,
46+
"club": "Drv"
47+
},
48+
"successCondition": {
49+
"nodeType": "PerformanceCenterScriptedConditions",
50+
"shots": 1
51+
},
52+
"skipOnSuccess": true
53+
},
54+
"ui": {
55+
"nodeType": "PerformanceCenterScriptedUI",
56+
"activeDataTiles": [ "Total", "Carry", "ClubSpeed", "BallSpeed" ],
57+
"shotListParameters": [ "Total", "Carry", "ClubSpeed", "BallSpeed" ],
58+
"defaultShotListParameter": "Total",
59+
"beforeShot": {
60+
"removeFrames": [ "Player", "Markers", "GoToSetup", "TargetCarry" ],
61+
"disableFrames": [ "Tiles", "ShotList", "GoToSetup", "Minimap" ]
62+
},
63+
"duringShot": {
64+
"removeFrames": [
65+
"Player",
66+
"Markers",
67+
"BroadcastTiles",
68+
"GoToSetup",
69+
"ClubDelivery"
70+
]
71+
},
72+
"afterShot": {
73+
"removeFrames": [ "Player", "Tiles", "ShotList", "Minimap", "GoToSetup", "Markers" ],
74+
"addFrames": [ "AllTiles" ]
75+
}
76+
}
77+
},
78+
{
79+
"nodeType": "PerformanceCenterScriptedStep",
80+
"id": "task-2-sample-id",
81+
"introMessage": {
82+
"header": "Shot 2",
83+
"description": "Hit a 7-iron for your approach shot",
84+
"seconds": 5
85+
},
86+
"successMessage": {
87+
"header": "Success!",
88+
"description": "",
89+
"seconds": 3
90+
},
91+
"failMessage": {
92+
"header": "Failed",
93+
"description": "",
94+
"seconds": 3
95+
},
96+
"logic": {
97+
"nodeType": "PerformanceCenterScriptedLogic",
98+
"setup": {
99+
"nodeType": "PerformanceCenterApproachScriptedSetup",
100+
"hole": 1,
101+
"pin": 3,
102+
"playerCategory": "Handicap",
103+
"hcp": 15,
104+
"gender": "Male",
105+
"minDistance": 150,
106+
"maxDistance": 150,
107+
"club": "_7I"
108+
},
109+
"successCondition": {
110+
"nodeType": "PerformanceCenterScriptedConditions",
111+
"shots": 1
112+
},
113+
"skipOnSuccess": true
114+
},
115+
"ui": {
116+
"nodeType": "PerformanceCenterScriptedUI",
117+
"activeDataTiles": [ "Total", "Carry", "ClubSpeed", "BallSpeed" ],
118+
"shotListParameters": [ "Total", "Carry", "ClubSpeed", "BallSpeed" ],
119+
"defaultShotListParameter": "Total",
120+
"beforeShot": {
121+
"removeFrames": [ "Player", "Markers", "GoToSetup", "TargetCarry" ],
122+
"disableFrames": [ "Tiles", "ShotList", "GoToSetup", "Minimap" ]
123+
},
124+
"duringShot": {
125+
"removeFrames": [
126+
"Player",
127+
"Markers",
128+
"BroadcastTiles",
129+
"GoToSetup",
130+
"ClubDelivery"
131+
]
132+
},
133+
"afterShot": {
134+
"removeFrames": [ "Player", "Tiles", "ShotList", "Minimap", "GoToSetup", "Markers" ],
135+
"addFrames": [ "AllTiles" ]
136+
}
137+
}
138+
},
139+
{
140+
"nodeType": "PerformanceCenterScriptedStep",
141+
"id": "task-3-sample-id",
142+
"introMessage": {
143+
"header": "Shot 3",
144+
"description": "Hit your driver off the tee",
145+
"seconds": 5
146+
},
147+
"successMessage": {
148+
"header": "Success!",
149+
"description": "",
150+
"seconds": 3
151+
},
152+
"failMessage": {
153+
"header": "Failed",
154+
"description": "",
155+
"seconds": 3
156+
},
157+
"logic": {
158+
"nodeType": "PerformanceCenterScriptedLogic",
159+
"setup": {
160+
"nodeType": "PerformanceCenterTeeShotsScriptedSetup",
161+
"hole": 2,
162+
"playerCategory": "Handicap",
163+
"hcp": 15,
164+
"gender": "Male",
165+
"courseDistance": 5000,
166+
"club": "Drv"
167+
},
168+
"successCondition": {
169+
"nodeType": "PerformanceCenterScriptedConditions",
170+
"shots": 1
171+
},
172+
"skipOnSuccess": true
173+
},
174+
"ui": {
175+
"nodeType": "PerformanceCenterScriptedUI",
176+
"activeDataTiles": [ "Total", "Carry", "ClubSpeed", "BallSpeed" ],
177+
"shotListParameters": [ "Total", "Carry", "ClubSpeed", "BallSpeed" ],
178+
"defaultShotListParameter": "Total",
179+
"beforeShot": {
180+
"removeFrames": [ "Player", "Markers", "GoToSetup", "TargetCarry" ],
181+
"disableFrames": [ "Tiles", "ShotList", "GoToSetup", "Minimap" ]
182+
},
183+
"duringShot": {
184+
"removeFrames": [
185+
"Player",
186+
"Markers",
187+
"BroadcastTiles",
188+
"GoToSetup",
189+
"ClubDelivery"
190+
]
191+
},
192+
"afterShot": {
193+
"removeFrames": [ "Player", "Tiles", "ShotList", "Minimap", "GoToSetup", "Markers" ],
194+
"addFrames": [ "AllTiles" ]
195+
}
196+
}
197+
},
198+
{
199+
"nodeType": "PerformanceCenterScriptedStep",
200+
"id": "task-4-sample-id",
201+
"introMessage": {
202+
"header": "Shot 4",
203+
"description": "Hit a PW for your approach shot",
204+
"seconds": 5
205+
},
206+
"successMessage": {
207+
"header": "Success!",
208+
"description": "",
209+
"seconds": 3
210+
},
211+
"failMessage": {
212+
"header": "Failed",
213+
"description": "",
214+
"seconds": 3
215+
},
216+
"logic": {
217+
"nodeType": "PerformanceCenterScriptedLogic",
218+
"setup": {
219+
"nodeType": "PerformanceCenterApproachScriptedSetup",
220+
"hole": 3,
221+
"pin": 1,
222+
"playerCategory": "Handicap",
223+
"hcp": 15,
224+
"gender": "Male",
225+
"minDistance": 150,
226+
"maxDistance": 150,
227+
"club": "_PW"
228+
},
229+
"successCondition": {
230+
"nodeType": "PerformanceCenterScriptedConditions",
231+
"shots": 1
232+
},
233+
"skipOnSuccess": true
234+
},
235+
"ui": {
236+
"nodeType": "PerformanceCenterScriptedUI",
237+
"activeDataTiles": [ "Total", "Carry", "ClubSpeed", "BallSpeed" ],
238+
"shotListParameters": [ "Total", "Carry", "ClubSpeed", "BallSpeed" ],
239+
"defaultShotListParameter": "Total",
240+
"beforeShot": {
241+
"removeFrames": [ "Player", "Markers", "GoToSetup", "TargetCarry" ],
242+
"disableFrames": [ "Tiles", "ShotList", "GoToSetup", "Minimap" ]
243+
},
244+
"duringShot": {
245+
"removeFrames": [
246+
"Player",
247+
"Markers",
248+
"BroadcastTiles",
249+
"GoToSetup",
250+
"ClubDelivery"
251+
]
252+
},
253+
"afterShot": {
254+
"removeFrames": [ "Player", "Tiles", "ShotList", "Minimap", "GoToSetup", "Markers" ],
255+
"addFrames": [ "AllTiles" ]
256+
}
257+
}
258+
}
259+
]
260+
}
261+
],
262+
"startMode": "Overwrite",
263+
"endMode": "Wait"
264+
}

0 commit comments

Comments
 (0)