@@ -10,6 +10,10 @@ import "./github-corner";
10
10
11
11
const GITHUB_URL = "https://github.com/Trikolon/url-classifier-exceptions-ui" ;
12
12
13
+ // Query parameter which can be used to override the RS environment.
14
+ const QUERY_PARAM_RS_ENV = "rs_env" ;
15
+
16
+ // The available Remote Settings endpoints.
13
17
const RS_ENDPOINTS = {
14
18
prod : "https://firefox.settings.services.mozilla.com" ,
15
19
stage : "https://firefox.settings.services.allizom.org" ,
@@ -18,6 +22,21 @@ const RS_ENDPOINTS = {
18
22
19
23
type RSEndpointKey = keyof typeof RS_ENDPOINTS ;
20
24
25
+ /**
26
+ * Get the RS environment from URL parameters, falling back to the defaults if
27
+ * not specified.
28
+ * @returns The RS environment key
29
+ */
30
+ function getRsEnv ( ) : RSEndpointKey {
31
+ const params = new URLSearchParams ( window . location . search ) ;
32
+ const env = params . get ( QUERY_PARAM_RS_ENV ) ;
33
+ if ( env && Object . keys ( RS_ENDPOINTS ) . includes ( env ) ) {
34
+ return env as RSEndpointKey ;
35
+ }
36
+ // Fall back to build env configuration or if env is not set, the default of "prod".
37
+ return ( import . meta. env . VITE_RS_ENVIRONMENT as RSEndpointKey ) || "prod" ;
38
+ }
39
+
21
40
/**
22
41
* Get the URL for the records endpoint for a given Remote Settings environment.
23
42
* @param rsOrigin The origin of the Remote Settings environment.
@@ -48,9 +67,10 @@ async function fetchRecords(rsOrigin: string): Promise<ExceptionListEntry[]> {
48
67
@customElement ( "app-root" )
49
68
export class App extends LitElement {
50
69
// The Remote Settings environment to use. The default is configured via env
51
- // at build time. The user can change this via a dropdown.
70
+ // at build time. The user can change this via a dropdown. The user can also
71
+ // override the environment via a query parameter.
52
72
@state ( )
53
- rsEnv : RSEndpointKey = ( import . meta . env . VITE_RS_ENVIRONMENT as RSEndpointKey ) || "prod" ;
73
+ rsEnv : RSEndpointKey = getRsEnv ( ) ;
54
74
55
75
// Holds all fetched records.
56
76
@state ( )
@@ -210,7 +230,16 @@ export class App extends LitElement {
210
230
< select
211
231
id ="rs-env "
212
232
@change =${ ( e : Event ) => {
213
- this . rsEnv = ( e . target as HTMLSelectElement ) . value as RSEndpointKey ;
233
+ const newEnv = ( e . target as HTMLSelectElement ) . value as RSEndpointKey ;
234
+ this . rsEnv = newEnv ;
235
+
236
+ // When the env changes reflect the update in the URL.
237
+ // Update URL parameter without reloading the page
238
+ const url = new URL ( window . location . href ) ;
239
+ url . searchParams . set ( QUERY_PARAM_RS_ENV , newEnv ) ;
240
+ window . history . pushState ( { } , "" , url ) ;
241
+
242
+ // Fetch the records again.
214
243
this . init ( ) ;
215
244
} }
216
245
>
0 commit comments