Skip to content

Commit f59be22

Browse files
stores & composables
1 parent 6074c6b commit f59be22

File tree

7 files changed

+43
-26
lines changed

7 files changed

+43
-26
lines changed

composables/api_fetch.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ export function api_fetch(
1212
const { valid, error } = validate_schema(schema, body)
1313

1414
if (!valid) {
15+
if (process.env.NODE_ENV === "development") {
16+
console.log("Bad request", error, schema, params)
17+
console.log("schema", schema)
18+
console.log("params", params)
19+
}
1520
feedback_store.add_error(400, schema.$id, "Bad request", error)
1621
throw new Error(schema.$id.concat(": ", error))
1722
}

composables/viewer_call.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ export function viewer_call(
88
const { valid, error } = validate_schema(schema, params)
99

1010
if (!valid) {
11+
if (process.env.NODE_ENV === "development") {
12+
console.log("Bad request", error, schema, params)
13+
console.log("schema", schema)
14+
console.log("params", params)
15+
}
1116
feedback_store.add_error(400, schema.route, "Bad request", error)
1217
throw new Error(schema.route.concat(": ", error))
1318
}

nuxt.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ export default defineNuxtConfig({
55
SITE_BRANCH:
66
process.env.NODE_ENV === "production" ? process.env.SITE_BRANCH : "",
77
PROJECT: process.env.NODE_ENV === "production" ? process.env.PROJECT : "",
8+
BROWSER: process.env.BROWSER || false,
9+
GEODE_PORT: process.env.GEODE_PORT || "",
10+
VIEWER_PORT: process.env.VIEWER_PORT || "",
811
},
912
},
1013

stores/geode.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Status from "@ogw_f/utils/status.js"
33

44
export const use_geode_store = defineStore("geode", {
55
state: () => ({
6-
port: "443",
6+
default_local_port: "5000",
77
request_counter: 0,
88
status: Status.NOT_CONNECTED,
99
}),
@@ -14,6 +14,15 @@ export const use_geode_store = defineStore("geode", {
1414
}
1515
return "http"
1616
},
17+
port() {
18+
if (use_infra_store().app_mode == appMode.appMode.CLOUD) {
19+
return "443"
20+
}
21+
if (useRuntimeConfig().public.GEODE_PORT) {
22+
return useRuntimeConfig().public.GEODE_PORT
23+
}
24+
return this.default_local_port
25+
},
1726
base_url() {
1827
const infra_store = use_infra_store()
1928
let geode_url = `${this.protocol}://${infra_store.domain_name}:${this.port}`
@@ -23,9 +32,6 @@ export const use_geode_store = defineStore("geode", {
2332
}
2433
geode_url += `/${infra_store.ID}/geode`
2534
}
26-
if (infra_store.app_mode == appMode.appMode.BROWSER) {
27-
geode_url += `/geode`
28-
}
2935
return geode_url
3036
},
3137
is_busy() {

stores/infra.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const use_infra_store = defineStore("infra", {
55
state: () => ({
66
app_mode: getAppMode(),
77
ID: useStorage("ID", ""),
8-
is_captcha_validated: this.app_mode == appMode.appMode.CLOUD ? false : true,
8+
is_captcha_validated: true,
99
status: Status.NOT_CREATED,
1010
}),
1111
getters: {
@@ -41,40 +41,33 @@ export const use_infra_store = defineStore("infra", {
4141
},
4242
actions: {
4343
async create_backend() {
44-
console.log("create_backend")
44+
console.log("create_backend this.app_mode", this.app_mode)
4545
if (this.status === Status.CREATED) return
46-
console.log("1")
4746
return navigator.locks.request("infra.create_backend", async (lock) => {
4847
this.status = Status.CREATING
4948
if (this.status === Status.CREATED) return
5049
console.log("LOCK GRANTED !", lock)
51-
// if (this.app_mode != appMode.BROWSER) {
52-
const geode_store = use_geode_store()
53-
const viewer_store = use_viewer_store()
54-
const feedback_store = use_feedback_store()
5550
if (this.app_mode == appMode.appMode.DESKTOP) {
56-
const back_port = await window.electronAPI.run_back(geode_store.port)
51+
const viewer_store = use_viewer_store()
52+
const geode_store = use_geode_store()
53+
const back_port = await window.electronAPI.run_back(geode_store.default_local_port)
5754
geode_store.$patch({ default_local_port: back_port })
58-
const viewer_port = await window.electronAPI.run_viewer(
59-
viewer_store.port,
60-
)
55+
const viewer_port = await window.electronAPI.run_viewer(viewer_store.default_local_port)
6156
viewer_store.$patch({ default_local_port: viewer_port })
62-
}
63-
if (this.app_mode == appMode.appMode.CLOUD) {
57+
} else if (this.app_mode == appMode.appMode.CLOUD) {
6458
const { data, error } = await useFetch(this.lambda_url, {
6559
method: "POST",
6660
})
6761
if (error.value || !data.value) {
6862
this.status = Status.NOT_CREATED
63+
const feedback_store = use_feedback_store()
6964
feedback_store.server_error = true
7065
return
7166
}
7267
this.ID = data.value.ID
7368
localStorage.setItem("ID", data.value.ID)
7469
}
75-
// }
7670
this.status = Status.CREATED
77-
console.log("this.status", this.status)
7871
return this.create_connection()
7972
})
8073
},

stores/viewer.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import vtkWSLinkClient from "@kitware/vtk.js/IO/Core/WSLinkClient"
33
import "@kitware/vtk.js/Rendering/OpenGL/Profiles/Geometry"
44
import schemas from "@geode/opengeodeweb-viewer/opengeodeweb_viewer_schemas.json"
55
import Status from "@ogw_f/utils/status.js"
6+
import { useRuntimeConfig } from "nuxt/app"
67

78
export const use_viewer_store = defineStore("viewer", {
89
state: () => ({
9-
port: "99",
10+
default_local_port: "1234",
1011
client: {},
1112
config: null,
1213
picking_mode: false,
@@ -22,19 +23,24 @@ export const use_viewer_store = defineStore("viewer", {
2223
return "ws"
2324
}
2425
},
26+
port() {
27+
if (use_infra_store().app_mode == appMode.appMode.CLOUD) {
28+
return "443"
29+
}
30+
if (useRuntimeConfig().public.VIEWER_PORT) {
31+
return useRuntimeConfig().public.VIEWER_PORT
32+
}
33+
return this.default_local_port
34+
},
2535
base_url() {
2636
const infra_store = use_infra_store()
27-
2837
let viewer_url = `${this.protocol}://${infra_store.domain_name}:${this.port}`
2938
if (infra_store.app_mode == appMode.appMode.CLOUD) {
3039
if (infra_store.ID == "") {
3140
throw new Error("ID must not be empty in cloud mode")
3241
}
3342
viewer_url += `/${infra_store.ID}/viewer`
3443
}
35-
if (infra_store.app_mode == appMode.appMode.BROWSER) {
36-
viewer_url += `/viewer`
37-
}
3844
viewer_url += "/ws"
3945
return viewer_url
4046
},

utils/app_mode.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ export const appMode = {
77
}
88

99
export function getAppMode() {
10-
console.log("getAppMode process.env", process.env)
1110
if (isElectron()) {
1211
return appMode.DESKTOP
1312
}
14-
if (process.env.BROWSER === true) {
13+
if (useRuntimeConfig().public.BROWSER === "true") {
1514
return appMode.BROWSER
1615
}
1716
return appMode.CLOUD

0 commit comments

Comments
 (0)