feat: Gitpod ready code(almost)

This commit is contained in:
Andras Bacsai
2022-07-11 20:32:27 +00:00
parent 77ae070c98
commit 1c65df282e
3 changed files with 22 additions and 2 deletions

View File

@@ -19,3 +19,6 @@ declare namespace App {
privatePort: string;
}
}
declare const GITPOD_WORKSPACE_URL: string

View File

@@ -1,8 +1,12 @@
import { browser, dev } from '$app/env';
import Cookies from 'js-cookie';
import { toast } from '@zerodevx/svelte-toast';
export function getAPIUrl() {
if (GITPOD_WORKSPACE_URL) {
const {href} = new URL(GITPOD_WORKSPACE_URL)
const newURL = href.replace('https://','https://3001-').replace(/\/$/,'')
return newURL
}
return dev ? 'http://localhost:3001' : 'http://localhost:3000';
}
async function send({
@@ -52,7 +56,7 @@ async function send({
}
if (dev && !path.startsWith('https://')) {
path = `http://localhost:3001${path}`;
path = `${getAPIUrl()}${path}`;
}
const response = await fetch(`${path}`, opts);