@@ -11,13 +11,27 @@ export const use_infra_store = defineStore("infra", {
1111 is_cloud ( ) {
1212 return ! isElectron ( ) && ! process . env . NODE_ENV === "development"
1313 } ,
14- domain_name ( ) {
15- if ( this . is_cloud ) {
14+ domain_name ( state ) {
15+ if ( state . is_cloud ) {
1616 return useRuntimeConfig ( ) . public . API_URL
1717 } else {
1818 return "localhost"
1919 }
2020 } ,
21+ lambda_url ( state ) {
22+ const geode_store = use_geode_store ( )
23+ const public_runtime_config = useRuntimeConfig ( ) . public
24+ const url =
25+ geode_store . protocol +
26+ "://" +
27+ state . domain_name +
28+ ":" +
29+ geode_store . port +
30+ public_runtime_config . SITE_BRANCH +
31+ public_runtime_config . PROJECT +
32+ "/createbackend"
33+ return url
34+ } ,
2135 is_running ( ) {
2236 return use_geode_store ( ) . is_running && use_viewer_store ( ) . is_running
2337 } ,
@@ -32,21 +46,14 @@ export const use_infra_store = defineStore("infra", {
3246 return
3347 }
3448 this . is_connexion_launched = true
35- if (
36- this . ID === "" ||
37- this . ID === null ||
38- typeof this . ID === "undefined"
39- ) {
49+ if ( [ "" , null ] . includes ( this . ID ) || typeof this . ID === "undefined" ) {
4050 return this . create_backend ( )
4151 } else {
42- const { data, error } = await useFetch ( `${ geode_store . base_url } /` , {
43- method : "POST" ,
44- } )
45- if ( data . value !== null ) {
46- geode_store . is_running = true
52+ try {
53+ await geode_store . do_ping ( )
4754 return geode_store . ping_task ( )
48- } else {
49- await this . create_backend ( )
55+ } catch ( e ) {
56+ return this . create_backend ( )
5057 }
5158 }
5259 } ,
@@ -56,17 +63,15 @@ export const use_infra_store = defineStore("infra", {
5663 const feedback_store = use_feedback_store ( )
5764
5865 if ( isElectron ( ) ) {
59- await window . electronAPI . run_back ( geode_store . PORT )
60- await window . electronAPI . run_viewer ( viewer_store . PORT )
66+ const back_port = await window . electronAPI . run_back ( geode_store . port )
67+ geode_store . $patch ( { default_local_port : back_port } )
68+ const viewer_port = await window . electronAPI . run_viewer (
69+ viewer_store . port ,
70+ )
71+ viewer_store . $patch ( { default_local_port : viewer_port } )
6172 return
6273 } else {
63- const public_runtime_config = useRuntimeConfig ( ) . public
64- const url = this . api_url . concat (
65- public_runtime_config . SITE_BRANCH ,
66- public_runtime_config . PROJECT ,
67- "/createbackend" ,
68- )
69- const { data, error } = await useFetch ( url , {
74+ const { data, error } = await useFetch ( this . lambda_url , {
7075 method : "POST" ,
7176 } )
7277 if ( data . value !== null ) {
0 commit comments