-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: status page improvements * feat: status page improvements * feat: status page improvements
- Loading branch information
1 parent
ff3cb20
commit 543e4fe
Showing
2 changed files
with
158 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { json } from '@sveltejs/kit'; | ||
|
||
export const GET = async ({ fetch, params }) => { | ||
const id: number = Number(params.id); | ||
console.log(`Fetching extended data of item ${id} from backend`); | ||
|
||
async function getExtendedData() { | ||
try { | ||
const res = await fetch(`http://127.0.0.1:8080/items/extended/${id}`); | ||
if (res.ok) { | ||
return await res.json(); | ||
} | ||
return { | ||
status: res.status, | ||
statusText: res.statusText | ||
}; | ||
} catch (e) { | ||
console.error(e); | ||
return { | ||
status: 503, | ||
statusText: 'Unable to fetch extended data. API is down.' | ||
}; | ||
} | ||
} | ||
|
||
const data = await getExtendedData(); | ||
|
||
return new Response(JSON.stringify(data), { | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters