Skip to content

Commit

Permalink
Use proxy for the API
Browse files Browse the repository at this point in the history
  • Loading branch information
boozec committed Jul 8, 2024
1 parent 78bb869 commit 9fbdcc9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
4 changes: 4 additions & 0 deletions ui/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ server {
location / {
try_files $uri $uri/ /index.html;
}

location /payments {
proxy_pass http://bankservice-api:8080;
}
}
32 changes: 16 additions & 16 deletions ui/src/stores/payment.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { defineStore } from 'pinia'
import { defineStore } from "pinia";

export const usePaymentStore = defineStore('payment', {
export const usePaymentStore = defineStore("payment", {
state: () => ({ data: {}, inloading: false }),
actions: {
async get(id) {
await fetch(`${import.meta.env.VITE_BACKEND_URL}/payments/${id}/`).then(async (response) => {
this.data = await response.json()
})
return this.data
await fetch(`/payments/${id}/`).then(async (response) => {
this.data = await response.json();
});
return this.data;
},
async pay(id) {
this.inloading = true
let result = 400
this.inloading = true;
let result = 400;

await fetch(`${import.meta.env.VITE_BACKEND_URL}/payments/${id}/pay/`, { method: 'POST' })
await fetch(`/payments/${id}/pay/`, { method: "POST" })
.then(async (response) => {
result = response.status
result = response.status;
})
.finally(() => {
this.inloading = false
})
this.inloading = false;
});

return result
}
}
})
return result;
},
},
});
21 changes: 11 additions & 10 deletions ui/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { fileURLToPath, URL } from 'node:url'
import { fileURLToPath, URL } from "node:url";

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
],
proxy: {
"/payments": "http://bankservice-api:8080",
},
plugins: [vue()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
})
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
});

0 comments on commit 9fbdcc9

Please sign in to comment.