File tree Expand file tree Collapse file tree 9 files changed +75
-37
lines changed Expand file tree Collapse file tree 9 files changed +75
-37
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ feature set and not require its own database.
41
41
You will need two domains, one for the Radicle Planning Boards and another for the Radicle Explorer.
42
42
43
43
1 . Deploy the ` radicle-planning-boards ` repository
44
- - Set the ` NUXT_PUBLIC_PARENT_ORIGIN ` environment variable to your Radicle Explorer domain
44
+ - Set the ` NUXT_PUBLIC_HOST_APP_ORIGIN ` environment variable to your Radicle Explorer domain
45
45
2 . Deploy the [ radicle-interface-with-planning-boards] ( https://github.com/maninak/radicle-interface-with-planning-boards )
46
46
repository
47
47
- Update ` src/config.json ` with your Radicle Planning Boards domain e.g.
@@ -60,6 +60,23 @@ repository
60
60
}
61
61
```
62
62
63
+ ### Configuring at runtime
64
+
65
+ You can overwrite ` NUXT_PUBLIC_HOST_APP_ORIGIN ` at runtime by creating a ` config.json `
66
+ file:
67
+
68
+ - inside the ` .output ` directory during deployment,
69
+ - or the ` public ` directory during development
70
+
71
+ Example:
72
+
73
+ ``` json
74
+ // config.json
75
+ {
76
+ "hostAppOrigin" : " http://localhost:3080"
77
+ }
78
+ ```
79
+
63
80
## Contributing
64
81
65
82
Please refer to the [ Contribution Guide] ( CONTRIBUTING.md ) .
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ const status = computed<ColumnCardStatus>(() => ({
21
21
icon: statusIconMap [props .issue .state .status ],
22
22
}))
23
23
24
- const hostAppBaseUrl = useHostAppBaseUrl ()
24
+ const hostAppOrigin = useHostAppOrigin ()
25
25
const isDebugging = useIsDebugging ()
26
26
27
27
// TODO: zac reduce duplication between ColumnIssueCard and ColumnPatchCard
@@ -53,7 +53,7 @@ const highlights = computed(() => {
53
53
const href = computed (() =>
54
54
new URL (
55
55
` /nodes/${route .params .node }/${route .params .rid }/issues/${props .issue .id } ` ,
56
- hostAppBaseUrl ,
56
+ hostAppOrigin ,
57
57
).toString (),
58
58
)
59
59
</script >
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ const status = computed<ColumnCardStatus>(() => ({
26
26
icon: statusIconMap [props .patch .state .status ],
27
27
}))
28
28
29
- const hostAppBaseUrl = useHostAppBaseUrl ()
29
+ const hostAppOrigin = useHostAppOrigin ()
30
30
const isDebugging = useIsDebugging ()
31
31
32
32
// TODO: zac reduce duplication between ColumnIssueCard and ColumnPatchCard
@@ -58,7 +58,7 @@ const highlights = computed(() => {
58
58
const href = computed (() =>
59
59
new URL (
60
60
` /nodes/${route .params .node }/${route .params .rid }/patches/${props .patch .id } ` ,
61
- hostAppBaseUrl ,
61
+ hostAppOrigin ,
62
62
).toString (),
63
63
)
64
64
</script >
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -31,14 +31,13 @@ const messageFromHostApp = v.union([
31
31
export type MessageFromHostApp = v . InferInput < typeof messageFromHostApp >
32
32
33
33
export function useHostAppMessaging ( ) {
34
- const { parentOrigin } = useRuntimeConfig ( ) . public
35
-
36
34
function onHostAppMessage < MessageType extends MessageFromHostApp [ 'type' ] > (
37
35
type : MessageType ,
38
36
callback : ( message : Extract < MessageFromHostApp , { type : MessageType } > ) => void ,
39
37
) : void {
40
- useEventListener ( 'message' , ( event ) => {
41
- if ( event . origin !== parentOrigin ) {
38
+ useEventListener ( 'message' , async ( event ) => {
39
+ const { hostAppOrigin } = await resolveConfig ( )
40
+ if ( event . origin !== hostAppOrigin ) {
42
41
return
43
42
}
44
43
@@ -51,8 +50,9 @@ export function useHostAppMessaging() {
51
50
} )
52
51
}
53
52
54
- function notifyHostApp ( message : MessageToHostApp ) : void {
55
- globalThis . window . parent . postMessage ( message , parentOrigin )
53
+ async function notifyHostApp ( message : MessageToHostApp ) : Promise < void > {
54
+ const { hostAppOrigin } = await resolveConfig ( )
55
+ globalThis . window . parent . postMessage ( message , hostAppOrigin )
56
56
}
57
57
58
58
return {
Original file line number Diff line number Diff line change
1
+ import { defaultHostAppOrigin } from '~/constants/config'
2
+
3
+ export function useHostAppOrigin ( ) : string {
4
+ const { data : hostAppOrigin } = useAsyncData ( 'config' , resolveConfig , {
5
+ transform : ( config ) => config . hostAppOrigin ,
6
+ } )
7
+
8
+ return hostAppOrigin . value ?? defaultHostAppOrigin
9
+ }
Original file line number Diff line number Diff line change 5
5
*/
6
6
export const defaultRadicleExplorerBaseUrl = 'https://explorer.radicle.gr/'
7
7
8
+ /**
9
+ * The default origin for the app hosting the iframe for this app
10
+ *
11
+ * Used for linking to the host app
12
+ */
13
+ export const defaultHostAppOrigin = 'http://localhost:3080'
14
+
8
15
/**
9
16
* The length of the hash value to keep when shortening it.
10
17
*
Original file line number Diff line number Diff line change 1
1
import process from 'node:process'
2
-
3
- const defaultParentOrigin = 'http://localhost:3080'
2
+ import { defaultHostAppOrigin } from './constants/config'
4
3
5
4
// https://nuxt.com/docs/api/configuration/nuxt-config
6
5
export default defineNuxtConfig ( {
@@ -20,11 +19,7 @@ export default defineNuxtConfig({
20
19
] ,
21
20
experimental : { typedPages : true } ,
22
21
devtools : { enabled : true } ,
23
- runtimeConfig : {
24
- public : {
25
- parentOrigin : defaultParentOrigin ,
26
- } ,
27
- } ,
22
+ runtimeConfig : { public : { hostAppOrigin : defaultHostAppOrigin } } ,
28
23
app : {
29
24
head : {
30
25
bodyAttrs : {
@@ -40,7 +35,7 @@ export default defineNuxtConfig({
40
35
contentSecurityPolicy : {
41
36
'frame-ancestors' : [
42
37
"'self'" ,
43
- process . env ?. [ 'NUXT_PUBLIC_PARENT_ORIGIN ' ] ?? defaultParentOrigin ,
38
+ process . env ?. [ 'NUXT_PUBLIC_HOST_APP_ORIGIN ' ] ?? defaultHostAppOrigin ,
44
39
] ,
45
40
} ,
46
41
xFrameOptions : false ,
Original file line number Diff line number Diff line change
1
+ import * as v from 'valibot'
2
+
3
+ interface Config {
4
+ hostAppOrigin : string
5
+ }
6
+
7
+ const jsonConfigSchema = v . object ( { hostAppOrigin : v . optional ( v . string ( ) ) } )
8
+
9
+ let config : Config | undefined
10
+
11
+ export async function resolveConfig ( ) : Promise < Config > {
12
+ if ( config ) {
13
+ return config
14
+ }
15
+
16
+ const { hostAppOrigin : publicHostAppOrigin } = useRuntimeConfig ( ) . public
17
+ const jsonConfig = await $fetch ( '/config.json' ) . catch ( ( ) => undefined )
18
+ const parseResult = v . safeParse ( jsonConfigSchema , jsonConfig )
19
+
20
+ if ( parseResult . success ) {
21
+ const hostAppOrigin = parseResult . output . hostAppOrigin ?? publicHostAppOrigin
22
+ config = { hostAppOrigin }
23
+ } else {
24
+ config = { hostAppOrigin : publicHostAppOrigin }
25
+ }
26
+
27
+ return config
28
+ }
You can’t perform that action at this time.
0 commit comments