Consistent build api url & updated base to /api/v1

This commit is contained in:
2022-12-29 23:39:56 +01:00
parent a936283be1
commit 469074d75b
6 changed files with 8 additions and 20 deletions

View File

@@ -1,11 +1,7 @@
import { dev } from '$app/environment';
import { buildApiUrl } from './apiUrl';
export default async function requestSessionCookie() {
let url = '/api';
if (dev) {
url = 'http://localhost:30010'.concat(url);
}
const url = buildApiUrl('/api/v1');
await fetch(url);
return true;
}

View File

@@ -1,14 +1,11 @@
<script lang="ts">
import LinkArrow from '$lib/components/LinkArrow.svelte';
import { buildApiUrl } from '$lib/utils/apiUrl';
export let isAdmin = false;
function logout() {
let url = '/api/logout';
if (window?.location?.href.includes('localhost')) {
url = 'http://localhost:30010'.concat(url);
}
const url = buildApiUrl('/api/v1/logout');
fetch(url, { method: 'POST' }).then((resp) => {
resp.status === 200 && window.location.reload();
});

View File

@@ -1,6 +1,7 @@
<script lang="ts">
import Button from '$lib/components/Button.svelte';
import Input from '$lib/components/Input.svelte';
import { buildApiUrl } from '$lib/utils/apiUrl';
let username: string;
let password: string;
@@ -20,11 +21,7 @@
}
};
let url = '/api/login';
if (window?.location?.href.includes('localhost')) {
url = 'http://localhost:30010'.concat(url);
}
const url = buildApiUrl('/api/v1/login');
fetch(url, options)
.then((resp) => {
const { status } = resp;

View File

@@ -52,7 +52,7 @@ function sitemapPages(): string {
}
async function sitemapShopPages(): Promise<string> {
const res = await fetch('/api/products');
const res = await fetch('/api/v1/products');
const productResponse: IProductsDTO = await res.json();
return productResponse?.products

View File

@@ -35,9 +35,7 @@ a {
text-decoration: none;
-webkit-transition: -webkit-transform 0.15s linear;
transition: -webkit-transform 0.15s linear;
transition: transform 0.15s linear;
transition: transform 0.15s linear, -webkit-transform 0.15s linear;
-webkit-transform-origin: 50% 80%;
transform-origin: 50% 80%;
}

View File

@@ -1,7 +1,7 @@
import type { PageServerLoad } from './$types';
export const load: PageServerLoad = async ({ fetch }) => {
const res = await fetch('/api/warehouse');
const res = await fetch('/api/v1/warehouse');
const warehouse = await res.json();
return {