@@ -5,16 +5,14 @@ import * as Runtime from "effect/Runtime"
55import { Effect , Option } from "effect-app"
66import { WebSdkLive } from "~/utils/observability"
77import "effect-app/builtin"
8- import { ref , shallowRef } from "vue"
8+ import { ref } from "vue"
99import { HttpClient } from "effect-app/http"
1010import { FetchHttpClient } from "@effect/platform"
1111import { ApiClientFactory } from "effect-app/client/apiClientFactory"
12- import { defineNuxtPlugin , useRuntimeConfig } from "nuxt/app"
12+ import { type useRuntimeConfig } from "nuxt/app"
1313
1414export const versionMatch = ref ( true )
1515
16- export const runtime = shallowRef < ReturnType < typeof makeRuntime > > ( )
17-
1816function makeRuntime ( feVersion : string , disableTracing : boolean ) {
1917 const apiLayers = ApiClientFactory . layer ( {
2018 url : "/api/api" ,
@@ -42,23 +40,26 @@ function makeRuntime(feVersion: string, disableTracing: boolean) {
4240 ) ,
4341 )
4442
43+ const globalLayers = disableTracing
44+ ? Layer . empty
45+ : WebSdkLive ( {
46+ serviceName : "effect-app-boilerplate-frontend" ,
47+ serviceVersion : feVersion ,
48+ attributes : { } ,
49+ } )
50+
4551 const rt : {
4652 runtime : Runtime . Runtime < RT >
4753 clean : ( ) => void
4854 } = initializeSync (
4955 // TODO: tracing when deployed
5056 disableTracing
5157 ? apiLayers
52- : apiLayers . pipe (
53- Layer . merge (
54- WebSdkLive ( {
55- serviceName : "effect-app-boilerplate-frontend" ,
56- serviceVersion : feVersion ,
57- attributes : { } ,
58- } ) ,
59- ) ,
60- ) ,
58+ : apiLayers . pipe ( Layer . provideMerge ( globalLayers ) ) ,
6159 )
60+
61+ //Atom.runtime.addGlobalLayer(globalLayers)
62+
6263 return {
6364 ...rt ,
6465 runFork : Runtime . runFork ( rt . runtime ) ,
@@ -71,13 +72,25 @@ function makeRuntime(feVersion: string, disableTracing: boolean) {
7172// TODO: make sure the runtime provides these
7273export type RT = ApiClientFactory
7374
74- export default defineNuxtPlugin ( _ => {
75- const config = useRuntimeConfig ( )
75+ /*
76+ We read the configuration from the global var sent by server, embedded in the html document.
77+ The reason for this is, that we want to have the configuration available before the Nuxt app is initialized.
78+ Otherwise we can only initialize the runtime in nuxt plugin, script setup or middleware,
79+ which means we cannot do anything with the runtime in the root of modules, etc.
7680
77- const rt = makeRuntime (
78- config . public . feVersion ,
79- config . public . env !== "local-dev" || ! config . public . telemetry ,
80- )
81+ Now we can use things like clientFor, which leverage the runtime, and export clients directly from modules.
82+ */
83+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
84+ const config = ( globalThis as any ) . __NUXT__ . config as ReturnType <
85+ typeof useRuntimeConfig
86+ >
87+ const isRemote = config . public . env !== "local-dev"
88+ const disableTracing = ! isRemote || ! config . public . telemetry
8189
82- runtime . value = rt
83- } )
90+ export const runtime = makeRuntime (
91+ config . public . feVersion ,
92+ disableTracing ,
93+ // config.public.env,
94+ // isRemote,
95+ // !isRemote && !config.public.telemetry,
96+ )
0 commit comments