RestURL static const

This commit is contained in:
s-prechtl 2023-01-20 15:34:36 +01:00
parent 8a538bb85f
commit c052d08e0e
4 changed files with 11 additions and 6 deletions

View file

@ -34,6 +34,7 @@ import Header from './components/Header.vue';
import "bootstrap/dist/css/bootstrap.min.css"; import "bootstrap/dist/css/bootstrap.min.css";
import "bootstrap/dist/js/bootstrap.min.js"; import "bootstrap/dist/js/bootstrap.min.js";
import Login from "@/components/Login.vue"; import Login from "@/components/Login.vue";
import {Rest} from "@/model/Rest";
export default defineComponent({ export default defineComponent({
name: 'App', name: 'App',
@ -49,14 +50,13 @@ export default defineComponent({
userScores: {}, userScores: {},
userId: 1, userId: 1,
user: null, user: null,
restUrl:'http://localhost:3000',
} }
}, },
methods: { methods: {
async fetchFromApi(path: string, method: "GET" | "POST") { 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(); return await res.json();
}, },
async fetchUserScores() { async fetchUserScores() {

View file

@ -19,7 +19,7 @@
import LeaderboardEntry from "@/components/LeaderboardEntry.vue"; import LeaderboardEntry from "@/components/LeaderboardEntry.vue";
import RRButton from "@/components/RRButton.vue"; import RRButton from "@/components/RRButton.vue";
import App from "@/App.vue"; import {Rest} from "@/model/Rest";
export default { export default {
name: "Leaderboard", name: "Leaderboard",
@ -45,7 +45,7 @@ export default {
}, },
methods: { methods: {
async fetchPage() { 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(); return await res.json();
}, },
title() { title() {

View file

@ -0,0 +1,3 @@
export class Rest {
static readonly URL = 'http://localhost:3000';
}

View file

@ -1,3 +1,5 @@
import {Rest} from "@/model/Rest";
export class User { export class User {
id?: number; id?: number;
name?: string; name?: string;
@ -8,7 +10,7 @@ export class User {
} }
static async getByName(name: string): Promise<User> { static async getByName(name: string): Promise<User> {
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(); return await res.json();
} }
@ -22,7 +24,7 @@ export class User {
"Content-Type": "application/json", "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', method: 'POST',
body: JSON.stringify(body), body: JSON.stringify(body),
headers: header, headers: header,