@cryptotaxi247 / CoPilot / commits / de6258a6

added api client

Davide Di Modica committed Aug 8, 2023 at 12:18 UTC de6258a61f08c2716991b551447cc0595a32b12a
8 files changed +55 -17
.env.production new
+1
@@ -0,0 +1 @@
1 +VITE_API_URL=http://127.0.0.1:5000
\ No newline at end of file
.prettierrc.json
+7 -7
@@ -1,8 +1,8 @@
1 {
2 - "arrowParens": "avoid",
3 - "printWidth": 140,
4 - "semi": false,
5 - "tabWidth": 4,
6 - "trailingComma": "none",
7 - "useTabs": false
8 -}
2 + "arrowParens": "avoid",
3 + "printWidth": 140,
4 + "semi": false,
5 + "tabWidth": 4,
6 + "trailingComma": "none",
7 + "useTabs": false
8 +}
\ No newline at end of file
src/api/connectors.ts new
+8
@@ -0,0 +1,8 @@
1 +import { HttpClient } from "./httpClient"
2 +
3 +export default {
4 + getAll() {
5 + // TODO: implement res type
6 + return HttpClient.get("/connectors")
7 + }
8 +}
src/api/httpClient.ts new
+26
@@ -0,0 +1,26 @@
1 +import axios from "axios"
2 +const BASE_URL = import.meta.env.VITE_API_URL
3 +
4 +export const HttpClient = axios.create({
5 + baseURL: BASE_URL
6 + // timeout: 2000,
7 + // headers: { "api-key": API_KEY }
8 +})
9 +
10 +// TODO: To be set when the authentication mechanism is implemented
11 +/*
12 +HttpClient.interceptors.response.use(
13 + response => {
14 + return response
15 + },
16 + error => {
17 + if (error.status === 401 || error.status === 412 || error.status === 409) {
18 + if (window.location.pathname.indexOf("login") === -1) {
19 + window.location.href = "/logout"
20 + }
21 + }
22 +
23 + return Promise.reject(error)
24 + }
25 +)
26 +*/
src/api/index.ts new
+5
@@ -0,0 +1,5 @@
1 +import connectors from "./connectors"
2 +
3 +export default {
4 + connectors
5 +}
src/empty.d.ts deleted
-1
@@ -1 +0,0 @@
1 -export {}
src/views/apps/Connectors.vue
+5 -5
@@ -303,6 +303,7 @@
303 <script>
304 import Affix from "@/components/Affix.vue"
305 import axios from "axios"
306 +import Api from "@/api"
307
308 import { defineComponent } from "@vue/runtime-core"
309 import { component } from "v-viewer"
@@ -390,7 +391,7 @@ export default defineComponent({
391 configureConnector(event) {
392 event.preventDefault()
393 const { connector_url, username, password, connector_api_key } = this.connectorForm
393 - const path = `http://localhost:5000/connectors/${this.currentConnector.id}`
394 + const path = `http://127.0.0.1:5000/connectors/${this.currentConnector.id}`
395 this.loading = true
396 this.closeDialogUserandPass()
397
@@ -470,7 +471,7 @@ export default defineComponent({
471 updateConnector(event) {
472 event.preventDefault()
473 const { connector_url, username, password, connector_api_key } = this.connectorForm
473 - const path = `http://localhost:5000/connectors/${this.currentConnector.id}`
474 + const path = `http://127.0.0.1:5000/connectors/${this.currentConnector.id}`
475 this.loading = true
476 this.closeUpdateModal()
477
@@ -549,10 +550,9 @@ export default defineComponent({
550 },
551
552 getConnectors() {
552 - const path = "http://localhost:5000/connectors"
553 this.loading = true
554 - axios
555 - .get(path)
554 + Api.connectors
555 + .getAll()
556 .then(res => {
557 this.connectors = res.data.connectors
558 })
tsconfig.json
+3 -4
@@ -8,17 +8,16 @@
8 "jsx": "preserve",
9 "sourceMap": true,
10 "resolveJsonModule": true,
11 - "isolatedModules": true,
11 + "isolatedModules": false,
12 "esModuleInterop": true,
13 "lib": ["esnext", "dom"],
14 "skipLibCheck": true,
15 "allowJs": true,
16 "paths": {
17 - "@/*": ["./src/*", "./dist/*"],
18 - "preact/*": ["./src/empty.d.ts"]
17 + "@/*": ["./src/*", "./dist/*"]
18 },
19 "types": ["vite/client", "node"]
20 },
22 - "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
21 + "include": ["src/**/*.ts", "src/**/*.js", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
22 "references": [{ "path": "./tsconfig.node.json" }]
23 }