Adjust API calls to use URL derived from getApiUrl() function

This commit is contained in:
Fred Boniface 2023-08-31 21:30:39 +01:00
parent b98c317ba4
commit f1acc9b97a
15 changed files with 31 additions and 16 deletions

View File

@ -6,6 +6,7 @@
import OverlayIsland from '$lib/islands/overlay-island.svelte'; import OverlayIsland from '$lib/islands/overlay-island.svelte';
import AlertBar from '$lib/ldb/nrcc/alert-bar.svelte'; import AlertBar from '$lib/ldb/nrcc/alert-bar.svelte';
import Island from '$lib/islands/island.svelte'; import Island from '$lib/islands/island.svelte';
import { getApiUrl } from '$lib/scripts/upstream';
let requestedStation; let requestedStation;
$: requestedStation = station; $: requestedStation = station;
@ -55,7 +56,7 @@
isLoading = true; // Set loading state isLoading = true; // Set loading state
try { try {
console.log(`Requested Station: ${requestedStation}`); console.log(`Requested Station: ${requestedStation}`);
const data = await fetch(`https://owlboard.info/api/v2/live/station/${requestedStation}/public`); const data = await fetch(`${getApiUrl()}/api/v2/live/station/${requestedStation}/public`);
jsonData = await data.json(); jsonData = await data.json();
} catch (error) { } catch (error) {
console.error('Error fetching data:', error); console.error('Error fetching data:', error);

View File

@ -4,6 +4,7 @@
import Reason from '$lib/raw-fetchers/reason.svelte'; import Reason from '$lib/raw-fetchers/reason.svelte';
import { uuid } from '$lib/stores/uuid'; import { uuid } from '$lib/stores/uuid';
import StylesToc from '$lib/train/styles-toc.svelte'; import StylesToc from '$lib/train/styles-toc.svelte';
import { getApiUrl } from '$lib/scripts/upstream';
export let detail = { export let detail = {
uid: '', uid: '',
rid: '', rid: '',
@ -19,7 +20,7 @@
async function getTrain(rid) { async function getTrain(rid) {
try { try {
console.log(`Requested Station: ${rid}`); console.log(`Requested Station: ${rid}`);
const url = `https://owlboard.info/api/v2/live/train/rid/${rid}`; const url = `${getApiUrl()}/api/v2/live/train/rid/${rid}`;
const opt = { const opt = {
method: 'GET', method: 'GET',
headers: { headers: {

View File

@ -1,3 +1,4 @@
import { getApiUrl } from './scripts/upstream';
import { uuid } from './stores/uuid'; import { uuid } from './stores/uuid';
export interface libauthResponse { export interface libauthResponse {
@ -50,7 +51,7 @@ async function checkUuid(): Promise<uuidCheckRes> {
} }
async function checkServerAuth(uuidString: string) { async function checkServerAuth(uuidString: string) {
const url = 'https://owlboard.info/api/v2/user/checkAuth'; const url = `${getApiUrl()}/api/v2/user/checkAuth`;
const options = { const options = {
method: 'GET', method: 'GET',
headers: { headers: {

View File

@ -1,4 +1,5 @@
<script> <script>
import { getApiUrl } from '$lib/scripts/upstream';
import { uuid } from '$lib/stores/uuid'; import { uuid } from '$lib/stores/uuid';
export let code = ''; export let code = '';
@ -17,7 +18,7 @@
} }
async function getReason(code = '') { async function getReason(code = '') {
const url = `https://owlboard.info/api/v2/ref/reasonCode/${code}`; const url = `${getApiUrl()}/api/v2/ref/reasonCode/${code}`;
const options = { const options = {
method: 'GET', method: 'GET',
headers: { headers: {

View File

@ -3,13 +3,14 @@
import { uuid } from '$lib/stores/uuid'; import { uuid } from '$lib/stores/uuid';
import LoadingText from '$lib/navigation/loading-text.svelte'; import LoadingText from '$lib/navigation/loading-text.svelte';
import StylesToc from './styles-toc.svelte'; import StylesToc from './styles-toc.svelte';
import { getApiUrl } from '$lib/scripts/upstream';
export let service = ''; export let service = '';
let isExpanded = false; let isExpanded = false;
async function getTrainByUID(tuid = '') { async function getTrainByUID(tuid = '') {
const url = `https://owlboard.info/api/v2/timetable/train/now/byTrainUid/${tuid}`; const url = `${getApiUrl()}/api/v2/timetable/train/now/byTrainUid/${tuid}`;
const options = { const options = {
method: 'GET', method: 'GET',
headers: { headers: {

View File

@ -2,6 +2,7 @@
import Header from '$lib/navigation/header.svelte'; import Header from '$lib/navigation/header.svelte';
import Loading from '$lib/navigation/loading.svelte'; import Loading from '$lib/navigation/loading.svelte';
import Nav from '$lib/navigation/nav.svelte'; import Nav from '$lib/navigation/nav.svelte';
import { getApiUrl } from '$lib/scripts/upstream';
const title = 'Location Codes'; const title = 'Location Codes';
let val = { let val = {
@ -16,7 +17,7 @@
let isLoading = false; let isLoading = false;
async function getData(type = '', value = '') { async function getData(type = '', value = '') {
const url = `https://owlboard.info/api/v2/ref/locationCode/${type}/${value}`; const url = `${getApiUrl()}/api/v2/ref/locationCode/${type}/${value}`;
const res = await fetch(url); const res = await fetch(url);
const data = await res.json(); const data = await res.json();
isLoading = false; isLoading = false;

View File

@ -3,6 +3,7 @@
import Header from '$lib/navigation/header.svelte'; import Header from '$lib/navigation/header.svelte';
import Loading from '$lib/navigation/loading.svelte'; import Loading from '$lib/navigation/loading.svelte';
import Nav from '$lib/navigation/nav.svelte'; import Nav from '$lib/navigation/nav.svelte';
import { getApiUrl } from '$lib/scripts/upstream';
import { uuid } from '$lib/stores/uuid.js'; import { uuid } from '$lib/stores/uuid.js';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
const title = 'Your Data'; const title = 'Your Data';
@ -18,7 +19,7 @@
async function fetchData() { async function fetchData() {
if ($uuid != 'null') { if ($uuid != 'null') {
const url = `https://owlboard.info/api/v2/user/${$uuid}`; const url = `${getApiUrl()}/api/v2/user/${$uuid}`;
const res = await fetch(url); const res = await fetch(url);
const json = await res.json(); const json = await res.json();
if (json.length) { if (json.length) {

View File

@ -4,6 +4,7 @@
import Nav from '$lib/navigation/nav.svelte'; import Nav from '$lib/navigation/nav.svelte';
import Loading from '$lib/navigation/loading.svelte'; import Loading from '$lib/navigation/loading.svelte';
import ResultIsland from '$lib/islands/result-island.svelte'; import ResultIsland from '$lib/islands/result-island.svelte';
import { getApiUrl } from '$lib/scripts/upstream';
const title = 'Reason Codes'; const title = 'Reason Codes';
let isLoading = false; let isLoading = false;
@ -25,7 +26,7 @@
async function getData() { async function getData() {
if (inputValue) { if (inputValue) {
const url = `https://owlboard.info/api/v2/ref/reasonCode/${inputValue}`; const url = `${getApiUrl()}/api/v2/ref/reasonCode/${inputValue}`;
const res = await fetch(url); const res = await fetch(url);
return await res.json(); return await res.json();
} else { } else {

View File

@ -5,6 +5,7 @@
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { checkAuth, logout } from '$lib/libauth'; import { checkAuth, logout } from '$lib/libauth';
import LogoutButton from '$lib/navigation/LogoutButton.svelte'; import LogoutButton from '$lib/navigation/LogoutButton.svelte';
import { getApiUrl } from '$lib/scripts/upstream';
const title = 'Register'; const title = 'Register';
@ -18,7 +19,7 @@
async function request() { async function request() {
isLoading = true; isLoading = true;
const url = 'https://owlboard.info/api/v2/user/request'; const url = `${getApiUrl()}/api/v2/user/request`;
const request = { const request = {
method: 'POST', method: 'POST',
headers: { headers: {

View File

@ -2,6 +2,7 @@
import Header from '$lib/navigation/header.svelte'; import Header from '$lib/navigation/header.svelte';
import Loading from '$lib/navigation/loading.svelte'; import Loading from '$lib/navigation/loading.svelte';
import Nav from '$lib/navigation/nav.svelte'; import Nav from '$lib/navigation/nav.svelte';
import { getApiUrl } from '$lib/scripts/upstream';
import { uuid } from '$lib/stores/uuid.js'; import { uuid } from '$lib/stores/uuid.js';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
@ -14,7 +15,7 @@
} }
async function submit(id) { async function submit(id) {
const url = 'https://owlboard.info/api/v2/user/register'; const url = `${getApiUrl()}/api/v2/user/register`;
const request = { const request = {
method: 'POST', method: 'POST',
headers: { headers: {

View File

@ -5,6 +5,7 @@
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import Loading from '$lib/navigation/loading.svelte'; import Loading from '$lib/navigation/loading.svelte';
import Done from '$lib/navigation/done.svelte'; import Done from '$lib/navigation/done.svelte';
import { getApiUrl } from '$lib/scripts/upstream';
const title = 'Report Issue'; const title = 'Report Issue';
let isLoading = false; let isLoading = false;
@ -47,7 +48,7 @@
`User Message:\n` + `User Message:\n` +
`${reportMsg}` `${reportMsg}`
}); });
const url = `https://owlboard.info/misc/issue`; const url = `${getApiUrl()}/misc/issue`;
const options = { const options = {
method: 'POST', method: 'POST',
headers: { headers: {

View File

@ -3,10 +3,11 @@
import Header from '$lib/navigation/header.svelte'; import Header from '$lib/navigation/header.svelte';
import Loading from '$lib/navigation/loading.svelte'; import Loading from '$lib/navigation/loading.svelte';
import Nav from '$lib/navigation/nav.svelte'; import Nav from '$lib/navigation/nav.svelte';
import { getApiUrl } from '$lib/scripts/upstream';
const title = 'Statistics'; const title = 'Statistics';
async function getData() { async function getData() {
const url = 'https://owlboard.info/misc/server/stats'; const url = `${getApiUrl()}/misc/server/stats`;
const res = await fetch(url); const res = await fetch(url);
return await res.json(); return await res.json();
} }

View File

@ -5,10 +5,11 @@
import Nav from '$lib/navigation/nav.svelte'; import Nav from '$lib/navigation/nav.svelte';
import LargeLogo from '$lib/images/large-logo.svelte'; import LargeLogo from '$lib/images/large-logo.svelte';
import { version, versionTag } from '$lib/stores/version'; import { version, versionTag } from '$lib/stores/version';
import { getApiUrl } from '$lib/scripts/upstream';
const title = 'Versions'; const title = 'Versions';
async function getData() { async function getData() {
const url = 'https://owlboard.info/misc/server/versions'; const url = `${getApiUrl()}/misc/server/versions`;
const res = await fetch(url); const res = await fetch(url);
return await res.json(); return await res.json();
} }

View File

@ -5,6 +5,7 @@
import Loading from '$lib/navigation/loading.svelte'; import Loading from '$lib/navigation/loading.svelte';
import { uuid } from '$lib/stores/uuid'; import { uuid } from '$lib/stores/uuid';
import StylesToc from '$lib/train/styles-toc.svelte'; import StylesToc from '$lib/train/styles-toc.svelte';
import { getApiUrl } from '$lib/scripts/upstream';
const title = 'PIS Finder'; const title = 'PIS Finder';
const variables = { title: 'Results' }; const variables = { title: 'Results' };
@ -18,14 +19,14 @@
async function findByStartEnd() { async function findByStartEnd() {
isLoading = true; isLoading = true;
const url = `https://owlboard.info/api/v2/pis/byStartEnd/${entryStartCRS}/${entryEndCRS}`; const url = `${getApiUrl()}/api/v2/pis/byStartEnd/${entryStartCRS}/${entryEndCRS}`;
await fetchData(url); await fetchData(url);
isLoading = false; isLoading = false;
} }
async function findByPis() { async function findByPis() {
isLoading = true; isLoading = true;
const url = `https://owlboard.info/api/v2/pis/byCode/${entryPIS}`; const url = `${getApiUrl()}/api/v2/pis/byCode/${entryPIS}`;
await fetchData(url); await fetchData(url);
isLoading = false; isLoading = false;
} }

View File

@ -7,6 +7,7 @@
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import TrainDetail from '$lib/train/train-detail.svelte'; import TrainDetail from '$lib/train/train-detail.svelte';
import { getApiUrl } from '$lib/scripts/upstream';
let title = 'Timetable Results'; let title = 'Timetable Results';
let id = ''; let id = '';
@ -50,7 +51,7 @@
uuid: $uuid uuid: $uuid
} }
}; };
const url = `https://owlboard.info/api/v2/timetable/train/${date}/${searchType}/${id}`; const url = `${getApiUrl()}/api/v2/timetable/train/${date}/${searchType}/${id}`;
try { try {
const res = await fetch(url, options); const res = await fetch(url, options);
if (res.status == 200) { if (res.status == 200) {