Added host address to .env

This commit is contained in:
Florian Sylvain
2022-12-22 02:52:50 +01:00
parent 659554c2a9
commit d3c68d6c89
7 changed files with 24 additions and 26 deletions
-11
View File
@@ -1,11 +0,0 @@
export interface Pong {
message: string;
}
export async function pingApi(): Promise<String> {
let result: String = ''
await fetch('http://localhost:8080/ping')
.then(response => response.json())
.then(jsonResponse => result = jsonResponse.message)
return result
}
+14 -6
View File
@@ -6,8 +6,18 @@ import { ref } from 'vue';
const email = ref('')
const password = ref('')
const baseURL = `http://${__APP_ENV__.APP_HOST_ADDRESS}:${__APP_ENV__.APP_API_PORT}`
function getArticles() {
fetch(`http://localhost:${__APP_ENV__.API_PORT}/articles/`, {
fetch(`${baseURL}/articles/`, {
headers: { "Authorization": `Bearer ${useAuthStore().token}` }
})
.then(response => response.json())
.then(result => console.log(result))
}
function ping() {
fetch(`${baseURL}/ping/`, {
headers: { "Authorization": `Bearer ${useAuthStore().token}` }
})
.then(response => response.json())
@@ -25,7 +35,7 @@ function jwtHandler(apiResponse: jwtFormat): void {
}
function login(email: string, password: string): void {
fetch(`http://localhost:${__APP_ENV__.API_PORT}/login/`, {
fetch(`${baseURL}/login/`, {
method: "POST",
body: JSON.stringify({
email: email,
@@ -54,10 +64,8 @@ function login(email: string, password: string): void {
<div>
<div>
<button @click="getArticles()">get all articles</button>
<button @click="getArticles()">get all articles</button>
<button @click="getArticles()">get all articles</button>
<button @click="getArticles()">get all articles</button>
<button class="button-primary" @click="getArticles()">get all articles</button>
<button class="button-primary" @click="ping()">ping</button>
</div>
</div>
</template>
+1 -1
View File
@@ -18,7 +18,7 @@ function jwtHandler(apiResponse: jwtFormat): void {
//TODO rempalcer tous les :8080 par la var d'env du port de l'API (sinon c un peu dommage)
function login(email: string, password: string): void {
fetch(`http://localhost:${__APP_ENV__.API_PORT}/login/`, {
fetch(`http://${__APP_ENV__.APP_HOST_ADDRESS}:${__APP_ENV__.APP_API_PORT}/login/`, {
method: "POST",
body: JSON.stringify({
email: email,