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 AlertBar from '$lib/ldb/nrcc/alert-bar.svelte';
import Island from '$lib/islands/island.svelte';
import { getApiUrl } from '$lib/scripts/upstream';
let requestedStation;
$: requestedStation = station;
@ -55,7 +56,7 @@
isLoading = true; // Set loading state
try {
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();
} catch (error) {
console.error('Error fetching data:', error);

View File

@ -4,6 +4,7 @@
import Reason from '$lib/raw-fetchers/reason.svelte';
import { uuid } from '$lib/stores/uuid';
import StylesToc from '$lib/train/styles-toc.svelte';
import { getApiUrl } from '$lib/scripts/upstream';
export let detail = {
uid: '',
rid: '',
@ -19,7 +20,7 @@
async function getTrain(rid) {
try {
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 = {
method: 'GET',
headers: {

View File

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

View File

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

View File

@ -3,13 +3,14 @@
import { uuid } from '$lib/stores/uuid';
import LoadingText from '$lib/navigation/loading-text.svelte';
import StylesToc from './styles-toc.svelte';
import { getApiUrl } from '$lib/scripts/upstream';
export let service = '';
let isExpanded = false;
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 = {
method: 'GET',
headers: {

View File

@ -2,6 +2,7 @@
import Header from '$lib/navigation/header.svelte';
import Loading from '$lib/navigation/loading.svelte';
import Nav from '$lib/navigation/nav.svelte';
import { getApiUrl } from '$lib/scripts/upstream';
const title = 'Location Codes';
let val = {
@ -16,7 +17,7 @@
let isLoading = false;
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 data = await res.json();
isLoading = false;

View File

@ -3,6 +3,7 @@
import Header from '$lib/navigation/header.svelte';
import Loading from '$lib/navigation/loading.svelte';
import Nav from '$lib/navigation/nav.svelte';
import { getApiUrl } from '$lib/scripts/upstream';
import { uuid } from '$lib/stores/uuid.js';
import { onMount } from 'svelte';
const title = 'Your Data';
@ -18,7 +19,7 @@
async function fetchData() {
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 json = await res.json();
if (json.length) {

View File

@ -4,6 +4,7 @@
import Nav from '$lib/navigation/nav.svelte';
import Loading from '$lib/navigation/loading.svelte';
import ResultIsland from '$lib/islands/result-island.svelte';
import { getApiUrl } from '$lib/scripts/upstream';
const title = 'Reason Codes';
let isLoading = false;
@ -25,7 +26,7 @@
async function getData() {
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);
return await res.json();
} else {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,6 +7,7 @@
import { onMount } from 'svelte';
import TrainDetail from '$lib/train/train-detail.svelte';
import { getApiUrl } from '$lib/scripts/upstream';
let title = 'Timetable Results';
let id = '';
@ -50,7 +51,7 @@
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 {
const res = await fetch(url, options);
if (res.status == 200) {