Skip to content

Commit a507071

Browse files
Merge pull request #135 from Geode-solutions/feat/ping_route
Feat/ping route
2 parents 972012d + cd56a3d commit a507071

24 files changed

+754
-325
lines changed

composables/api_fetch.js

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,41 +29,46 @@ export function api_fetch(
2929
if (schema.max_retry) {
3030
request_options.max_retry = schema.max_retry
3131
}
32-
return useFetch(schema.$id, {
33-
baseURL: geode_store.base_url,
34-
...request_options,
35-
onRequestError({ error }) {
36-
geode_store.stop_request()
37-
feedback_store.add_error(
38-
error.code,
39-
schema.$id,
40-
error.message,
41-
error.stack,
42-
)
43-
if (request_error_function) {
44-
request_error_function(error)
45-
}
46-
},
47-
onResponse({ response }) {
48-
if (response.ok) {
49-
geode_store.stop_request()
50-
if (response_function) {
51-
response_function(response)
32+
return new Promise((resolve, reject) => {
33+
useFetch(schema.$id, {
34+
baseURL: geode_store.base_url,
35+
...request_options,
36+
async onRequestError({ error }) {
37+
await geode_store.stop_request()
38+
await feedback_store.add_error(
39+
error.code,
40+
schema.$id,
41+
error.message,
42+
error.stack,
43+
)
44+
if (request_error_function) {
45+
await request_error_function(error)
5246
}
53-
}
54-
},
55-
onResponseError({ response }) {
56-
geode_store.stop_request()
57-
feedback_store.add_error(
58-
response.status,
59-
schema.$id,
60-
response._data.name,
61-
response._data.description,
62-
)
63-
if (response_error_function) {
64-
response_error_function(response)
65-
}
66-
},
47+
reject(error)
48+
},
49+
async onResponse({ response }) {
50+
if (response.ok) {
51+
await geode_store.stop_request()
52+
if (response_function) {
53+
await response_function(response)
54+
}
55+
resolve(response)
56+
}
57+
},
58+
async onResponseError({ response }) {
59+
await geode_store.stop_request()
60+
await feedback_store.add_error(
61+
response.status,
62+
schema.$id,
63+
response._data.name,
64+
response._data.description,
65+
)
66+
if (response_error_function) {
67+
await response_error_function(response)
68+
}
69+
reject(response)
70+
},
71+
})
6772
})
6873
}
6974

nuxt.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ export default defineNuxtConfig({
99
},
1010
},
1111

12-
modules: [["@pinia/nuxt", { autoImports: ["defineStore"] }], "@vueuse/nuxt"],
12+
modules: [
13+
["@pinia/nuxt", { autoImports: ["defineStore", "storeToRefs"] }],
14+
"@vueuse/nuxt",
15+
],
1316
imports: {
1417
dirs: ["stores"],
1518
},

package.json

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
"geode_objects": "node scripts/generate_geode_objects.js && prettier ./assets/geode_objects.js --write"
88
},
99
"devDependencies": {
10-
"@nuxt/test-utils": "^3.13.1",
11-
"@vitejs/plugin-vue": "^5.0.5",
10+
"@nuxt/test-utils": "^3.14.1",
11+
"@pinia/testing": "^0.1.5",
12+
"@vitejs/plugin-vue": "^5.1.3",
1213
"@vitest/coverage-v8": "^1.6.0",
1314
"@vue/test-utils": "^2.4.6",
1415
"eslint": "^8.57.0",
@@ -28,6 +29,7 @@
2829
"vite-plugin-vuetify": "^2.0.3",
2930
"vitest": "^1.6.0",
3031
"vitest-environment-nuxt": "^1.0.0",
32+
"vuetify": "^3.6.9",
3133
"wslink": "1.12.4"
3234
},
3335
"overrides": {
@@ -38,22 +40,21 @@
3840
"version": "0.0.0-semantically-released",
3941
"main": "./nuxt.config.js",
4042
"dependencies": {
41-
"@geode/opengeodeweb-back": "4.3.0",
42-
"@geode/opengeodeweb-viewer": "0.1.2",
43+
"@geode/opengeodeweb-back": "5.0.0-rc.1",
44+
"@geode/opengeodeweb-viewer": "0.2.0",
4345
"@kitware/vtk.js": "30.3.1",
4446
"@mdi/font": "^7.4.47",
45-
"@pinia/nuxt": "^0.5.1",
46-
"@types/node": "^20.14.2",
47-
"@vueuse/components": "^10.11.0",
48-
"@vueuse/nuxt": "^10.11.0",
49-
"ajv": "^8.16.0",
47+
"@pinia/nuxt": "^0.5.4",
48+
"@types/node": "^22.5.1",
49+
"@vueuse/components": "^11.0.3",
50+
"@vueuse/nuxt": "^11.0.3",
51+
"ajv": "^8.17.1",
5052
"is-electron": "^2.2.2",
51-
"pinia": "^2.1.7",
52-
"sass": "^1.77.5",
53-
"semver": "^7.6.2",
53+
"pinia": "^2.2.2",
54+
"sass": "^1.77.8",
55+
"semver": "^7.6.3",
5456
"vue-recaptcha": "^2.0.3",
55-
"vue3-carousel": "^0.3.3",
56-
"vuetify": "^3.6.9"
57+
"vue3-carousel": "^0.3.3"
5758
},
5859
"repository": {
5960
"type": "git",

stores/feedback.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ export const use_feedback_store = defineStore("feedback", {
44
server_error: false,
55
}),
66
actions: {
7-
add_error(code, route, name, description) {
8-
this.feedbacks.push({
7+
async add_error(code, route, name, description) {
8+
await this.feedbacks.push({
99
type: "error",
1010
code,
1111
route,
1212
name,
1313
description,
1414
})
1515
},
16-
add_success(description) {
17-
this.feedbacks.push({
16+
async add_success(description) {
17+
await this.feedbacks.push({
1818
type: "success",
1919
description,
2020
})
2121
},
22-
delete_feedback(feedback_index) {
23-
this.feedbacks.splice(feedback_index, 1)
22+
async delete_feedback(feedback_index) {
23+
await this.feedbacks.splice(feedback_index, 1)
2424
},
25-
delete_server_error() {
25+
async delete_server_error() {
2626
this.server_error = false
2727
},
2828
},

stores/geode.js

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
1+
import back_schemas from "@geode/opengeodeweb-back/schemas.json"
2+
13
export const use_geode_store = defineStore("geode", {
24
state: () => ({
3-
PROTOCOL: use_infra_store().is_cloud ? "https" : "http",
4-
PORT: use_infra_store().is_cloud ? "443" : "5000",
5+
default_local_port: "5000",
56
request_counter: 0,
67
is_running: false,
78
}),
89
getters: {
10+
protocol() {
11+
if (use_infra_store().is_cloud) {
12+
return "https"
13+
} else {
14+
return "http"
15+
}
16+
},
17+
port() {
18+
if (use_infra_store().is_cloud) {
19+
return "443"
20+
} else {
21+
return this.default_local_port
22+
}
23+
},
924
base_url() {
1025
const infra_store = use_infra_store()
11-
const api_url = infra_store.api_url
12-
var geode_url = `${api_url}`
26+
var geode_url = `${this.protocol}://${infra_store.domain_name}:${this.port}`
1327
if (infra_store.is_cloud) {
28+
if (infra_store.ID == "") {
29+
throw new Error("ID must not be empty in cloud mode")
30+
}
1431
geode_url += `/${infra_store.ID}/geode`
1532
}
1633
return geode_url
@@ -25,16 +42,22 @@ export const use_geode_store = defineStore("geode", {
2542
},
2643
async do_ping() {
2744
const feedback_store = use_feedback_store()
28-
const { data } = await useFetch(`${this.base_url}/ping`, {
29-
method: "POST",
30-
})
31-
if (data.value !== null) {
32-
this.is_running = true
33-
return
34-
} else {
35-
feedback_store.$patch({ server_error: true })
36-
return
37-
}
45+
await api_fetch(
46+
{ schema: back_schemas.opengeodeweb_back.ping, params: {} },
47+
{
48+
request_error_function: async () => {
49+
await feedback_store.$patch({ server_error: true })
50+
this.is_running = false
51+
},
52+
response_function: async () => {
53+
this.is_running = true
54+
},
55+
response_error_function: async () => {
56+
await feedback_store.$patch({ server_error: true })
57+
this.is_running = false
58+
},
59+
},
60+
)
3861
},
3962
start_request() {
4063
this.request_counter++

stores/infra.js

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,26 @@ 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-
22-
api_url() {
21+
lambda_url(state) {
2322
const geode_store = use_geode_store()
2423
const public_runtime_config = useRuntimeConfig().public
25-
if (public_runtime_config.NODE_ENV == "test") {
26-
return ""
27-
}
28-
var api_url = `${geode_store.PROTOCOL}://${this.domain_name}:${geode_store.PORT}`
29-
return api_url
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
3034
},
3135
is_running() {
3236
return use_geode_store().is_running && use_viewer_store().is_running
@@ -42,21 +46,14 @@ export const use_infra_store = defineStore("infra", {
4246
return
4347
}
4448
this.is_connexion_launched = true
45-
if (
46-
this.ID === "" ||
47-
this.ID === null ||
48-
typeof this.ID === "undefined"
49-
) {
49+
if (["", null].includes(this.ID) || typeof this.ID === "undefined") {
5050
return this.create_backend()
5151
} else {
52-
const { data, error } = await useFetch(`${geode_store.base_url}/`, {
53-
method: "POST",
54-
})
55-
if (data.value !== null) {
56-
geode_store.is_running = true
52+
try {
53+
await geode_store.do_ping()
5754
return geode_store.ping_task()
58-
} else {
59-
await this.create_backend()
55+
} catch (e) {
56+
return this.create_backend()
6057
}
6158
}
6259
},
@@ -66,19 +63,15 @@ export const use_infra_store = defineStore("infra", {
6663
const feedback_store = use_feedback_store()
6764

6865
if (isElectron()) {
69-
await window.electronAPI.run_back(geode_store.PORT)
70-
await window.electronAPI.run_viewer(viewer_store.PORT)
71-
// geode_store.$patch({ is_running: true })
72-
// viewer_store.$patch({ is_running: true })
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 })
7372
return
7473
} else {
75-
const public_runtime_config = useRuntimeConfig().public
76-
const url = this.api_url.concat(
77-
public_runtime_config.SITE_BRANCH,
78-
public_runtime_config.PROJECT,
79-
"/createbackend",
80-
)
81-
const { data, error } = await useFetch(url, {
74+
const { data, error } = await useFetch(this.lambda_url, {
8275
method: "POST",
8376
})
8477
if (data.value !== null) {

stores/viewer.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import schemas from "@geode/opengeodeweb-viewer/schemas.json"
55

66
export const use_viewer_store = defineStore("viewer", {
77
state: () => ({
8-
PROTOCOL: use_infra_store().is_cloud ? "wss" : "ws",
9-
PORT: use_infra_store().is_cloud ? "443" : "1234",
8+
default_local_port: "1234",
109
client: {},
1110
config: null,
1211
is_running: false,
@@ -15,10 +14,27 @@ export const use_viewer_store = defineStore("viewer", {
1514
request_counter: 0,
1615
}),
1716
getters: {
17+
protocol() {
18+
if (use_infra_store().is_cloud) {
19+
return "wss"
20+
} else {
21+
return "ws"
22+
}
23+
},
24+
port(state) {
25+
if (use_infra_store().is_cloud) {
26+
return "443"
27+
} else {
28+
return state.default_local_port
29+
}
30+
},
1831
base_url(state) {
1932
const infra_store = use_infra_store()
20-
var viewer_url = `${state.PROTOCOL}://${infra_store.domain_name}:${state.PORT}`
33+
let viewer_url = `${state.protocol}://${infra_store.domain_name}:${state.port}`
2134
if (infra_store.is_cloud) {
35+
if (infra_store.ID == "") {
36+
throw new Error("ID must not be empty in cloud mode")
37+
}
2238
viewer_url += `/${infra_store.ID}/viewer`
2339
}
2440
viewer_url += "/ws"

0 commit comments

Comments
 (0)