diff --git a/frontend/src/App.vue b/frontend/src/App.vue index a740596..0901f30 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -34,6 +34,7 @@ import Header from './components/Header.vue'; import "bootstrap/dist/css/bootstrap.min.css"; import "bootstrap/dist/js/bootstrap.min.js"; import Login from "@/components/Login.vue"; +import {Rest} from "@/model/Rest"; export default defineComponent({ name: 'App', @@ -49,14 +50,13 @@ export default defineComponent({ userScores: {}, userId: 1, user: null, - restUrl:'http://localhost:3000', } }, methods: { async fetchFromApi(path: string, method: "GET" | "POST") { - let res: Response = await fetch(this.restUrl + path, {method: method,}); + let res: Response = await fetch(Rest.URL + path, {method: method,}); return await res.json(); }, async fetchUserScores() { diff --git a/frontend/src/components/Leaderboard.vue b/frontend/src/components/Leaderboard.vue index 33d6ffc..1b492c1 100644 --- a/frontend/src/components/Leaderboard.vue +++ b/frontend/src/components/Leaderboard.vue @@ -19,7 +19,7 @@ import LeaderboardEntry from "@/components/LeaderboardEntry.vue"; import RRButton from "@/components/RRButton.vue"; -import App from "@/App.vue"; +import {Rest} from "@/model/Rest"; export default { name: "Leaderboard", @@ -45,7 +45,7 @@ export default { }, methods: { async fetchPage() { - let res = await fetch(`${App.data().restUrl}/leaderboard/${this.type}?pagination=true&entriesPerPage=${this.entriesPerPage}&page=${this.pageNumber}`, {method: "GET"}); + let res = await fetch(`${Rest.URL}/leaderboard/${this.type}?pagination=true&entriesPerPage=${this.entriesPerPage}&page=${this.pageNumber}`, {method: "GET"}); return await res.json(); }, title() { diff --git a/frontend/src/model/Rest.ts b/frontend/src/model/Rest.ts new file mode 100644 index 0000000..53b902e --- /dev/null +++ b/frontend/src/model/Rest.ts @@ -0,0 +1,3 @@ +export class Rest { + static readonly URL = 'http://localhost:3000'; +} \ No newline at end of file diff --git a/frontend/src/model/User.ts b/frontend/src/model/User.ts index 61518ea..38f83be 100644 --- a/frontend/src/model/User.ts +++ b/frontend/src/model/User.ts @@ -1,3 +1,5 @@ +import {Rest} from "@/model/Rest"; + export class User { id?: number; name?: string; @@ -8,7 +10,7 @@ export class User { } static async getByName(name: string): Promise { - let res: Response = await fetch('http://localhost:3000/user/' + name, {method: 'GET'}); + let res: Response = await fetch(Rest.URL + '/user/' + name, {method: 'GET'}); return await res.json(); } @@ -22,7 +24,7 @@ export class User { "Content-Type": "application/json", }; - let res: Response = await fetch('http://localhost:3000/user/register', { + let res: Response = await fetch( Rest.URL + '/user/register', { method: 'POST', body: JSON.stringify(body), headers: header,