diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..c08a8f8 --- /dev/null +++ b/.env.example @@ -0,0 +1,7 @@ +# Extiri Web Environment Variables +# +# Copy this file to .env and adjust values as needed. +# Environment variables prefixed with PUBLIC_ are exposed to the client. + +# Base URL for the Extiri API (no trailing slash) +PUBLIC_API_BASE_URL=https://extiri.com diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index d7a1047..d625ea2 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -6,6 +6,7 @@ import escape from 'lodash.escape'; import md5 from 'md5'; import CodeMirror from '../CodeMirror.svelte'; + import { PUBLIC_API_BASE_URL } from '$env/static/public'; const browser = typeof localStorage !== 'undefined'; @@ -176,7 +177,7 @@ async function getSnippets() { isLoading = true; - let api = 'https://extiri.com/api/1/snippets/?'; + let api = `${PUBLIC_API_BASE_URL}/api/1/snippets/?`; api = api + 'page=' + currentPage; @@ -307,7 +308,7 @@ async function getUserDetail() { let token = getToken(); - let response = await fetch('https://extiri.com/api/1/users/me/', { + let response = await fetch(`${PUBLIC_API_BASE_URL}/api/1/users/me/`, { headers: { Authorization: 'Bearer ' + token } }); @@ -361,7 +362,7 @@
- +
{#if isLoggedIn} diff --git a/src/routes/account/+page.svelte b/src/routes/account/+page.svelte index ca7ca31..7b0fff2 100644 --- a/src/routes/account/+page.svelte +++ b/src/routes/account/+page.svelte @@ -4,6 +4,7 @@ import { goto } from '$app/navigation'; import md5 from 'md5'; import escape from 'lodash.escape'; + import { PUBLIC_API_BASE_URL } from '$env/static/public'; const browser = typeof window !== 'undefined'; @@ -72,7 +73,7 @@ password: newUserPassword }; - let response = await fetch('https://extiri.com/api/1/users/signup/', { + let response = await fetch(`${PUBLIC_API_BASE_URL}/api/1/users/signup/`, { method: 'POST', headers: { 'Content-Type': 'application/json' @@ -106,7 +107,7 @@ password: loginPassword }; - let response = await fetch('https://extiri.com/api/1/users/delete/', { + let response = await fetch(`${PUBLIC_API_BASE_URL}/api/1/users/delete/`, { method: 'DELETE', headers: { 'Content-Type': 'application/json' @@ -148,7 +149,7 @@ let encodedCredentials = window.btoa(credentials.email + ':' + credentials.password); - let response = await fetch('https://extiri.com/api/1/users/login/', { + let response = await fetch(`${PUBLIC_API_BASE_URL}/api/1/users/login/`, { method: 'POST', headers: { Authorization: 'Basic ' + encodedCredentials, @@ -215,7 +216,7 @@ async function getUserDetail() { let token = getToken(); - let response = await fetch('https://extiri.com/api/1/users/me/', { + let response = await fetch(`${PUBLIC_API_BASE_URL}/api/1/users/me/`, { headers: { Authorization: 'Bearer ' + token } @@ -390,7 +391,7 @@ I agree to the - Terms of Service. diff --git a/src/routes/create/+page.svelte b/src/routes/create/+page.svelte index a6ca8ed..bac0c63 100644 --- a/src/routes/create/+page.svelte +++ b/src/routes/create/+page.svelte @@ -5,6 +5,7 @@ import CodeMirror from '../../CodeMirrorEditor.svelte'; import { languages } from '../../langStyles.js'; import { languageStore } from '../../store.js'; + import { PUBLIC_API_BASE_URL } from '$env/static/public'; const categories = ['None', 'UI', 'Math', 'Collections', 'Automations', 'Debugging']; @@ -51,7 +52,7 @@ code: code }; - let response = await fetch('https://extiri.com/api/1/snippets/create/', { + let response = await fetch(`${PUBLIC_API_BASE_URL}/api/1/snippets/create/`, { method: 'POST', headers: { Authorization: 'Bearer ' + getToken(), diff --git a/src/routes/snippet/+page.svelte b/src/routes/snippet/+page.svelte index e9365f3..f2d9a5f 100644 --- a/src/routes/snippet/+page.svelte +++ b/src/routes/snippet/+page.svelte @@ -260,6 +260,7 @@ import escape from 'lodash.escape'; import CodeMirror from '../../CodeMirror.svelte'; import sdk from '@stackblitz/sdk'; + import { PUBLIC_API_BASE_URL } from '$env/static/public'; const browser = typeof window !== 'undefined'; @@ -522,7 +523,7 @@ } async function getUser(id: string) { - let response = await fetch('https://extiri.com/api/1/users/get/' + id); + let response = await fetch(`${PUBLIC_API_BASE_URL}/api/1/users/get/` + id); if (response.ok) { let user = await (response.json() as Promise); @@ -536,7 +537,7 @@ async function getSnippetsDetail() { if (browser) { id = window.location.toString().split('?')[1]; - let response = await fetch('https://extiri.com/api/1/snippets/get/' + id); + let response = await fetch(`${PUBLIC_API_BASE_URL}/api/1/snippets/get/` + id); if (response.ok) { let snippet = await (response.json() as Promise); @@ -562,7 +563,7 @@ } id = window.location.toString().split('?')[1]; - let response = await fetch('https://extiri.com/api/1/snippets/delete/' + id, { + let response = await fetch(`${PUBLIC_API_BASE_URL}/api/1/snippets/delete/` + id, { method: 'DELETE', headers: { Authorization: 'Bearer ' + getToken() } }); @@ -592,7 +593,7 @@ async function checkIfCreator() { let token = getToken(); - let response = await fetch('https://extiri.com/api/1/users/me/', { + let response = await fetch(`${PUBLIC_API_BASE_URL}/api/1/users/me/`, { headers: { Authorization: 'Bearer ' + token } });