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() { export default async function requestSessionCookie() {
let url = '/api'; const url = buildApiUrl('/api/v1');
if (dev) {
url = 'http://localhost:30010'.concat(url);
}
await fetch(url); await fetch(url);
return true; return true;
} }

View File

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

View File

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

View File

@@ -52,7 +52,7 @@ function sitemapPages(): string {
} }
async function sitemapShopPages(): Promise<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(); const productResponse: IProductsDTO = await res.json();
return productResponse?.products return productResponse?.products

View File

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

View File

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