mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-22 14:29:36 +02:00
Add continent code to the country cards
This commit is contained in:
parent
bdb37c5ca1
commit
2d7fe56086
3 changed files with 106 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
import { getFlag } from '$lib';
|
import { continentCodeToString, getFlag } from '$lib';
|
||||||
import type { Country } from '$lib/types';
|
import type { Country } from '$lib/types';
|
||||||
import { createEventDispatcher } from 'svelte';
|
import { createEventDispatcher } from 'svelte';
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
@ -21,6 +21,7 @@
|
||||||
</figure>
|
</figure>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h2 class="card-title overflow-ellipsis">{country.name}</h2>
|
<h2 class="card-title overflow-ellipsis">{country.name}</h2>
|
||||||
|
<div class="badge badge-primary">{continentCodeToString(country.continent)}</div>
|
||||||
<div class="card-actions justify-end">
|
<div class="card-actions justify-end">
|
||||||
<!-- <button class="btn btn-info" on:click={moreInfo}>More Info</button> -->
|
<!-- <button class="btn btn-info" on:click={moreInfo}>More Info</button> -->
|
||||||
<button class="btn btn-primary" on:click={nav}>Open</button>
|
<button class="btn btn-primary" on:click={nav}>Open</button>
|
||||||
|
|
|
@ -177,3 +177,24 @@ export function groupChecklistsByDate(
|
||||||
|
|
||||||
return groupedChecklists;
|
return groupedChecklists;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function continentCodeToString(code: string) {
|
||||||
|
switch (code) {
|
||||||
|
case 'AF':
|
||||||
|
return 'Africa';
|
||||||
|
case 'AN':
|
||||||
|
return 'Antarctica';
|
||||||
|
case 'AS':
|
||||||
|
return 'Asia';
|
||||||
|
case 'EU':
|
||||||
|
return 'Europe';
|
||||||
|
case 'NA':
|
||||||
|
return 'North America';
|
||||||
|
case 'OC':
|
||||||
|
return 'Oceania';
|
||||||
|
case 'SA':
|
||||||
|
return 'South America';
|
||||||
|
default:
|
||||||
|
return 'Unknown';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
83
frontend/src/routes/auth/[...path]/+server.ts
Normal file
83
frontend/src/routes/auth/[...path]/+server.ts
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
const PUBLIC_SERVER_URL = process.env['PUBLIC_SERVER_URL'];
|
||||||
|
const endpoint = PUBLIC_SERVER_URL || 'http://localhost:8000';
|
||||||
|
import { json } from '@sveltejs/kit';
|
||||||
|
|
||||||
|
/** @type {import('./$types').RequestHandler} */
|
||||||
|
export async function GET({ url, params, request, fetch, cookies }) {
|
||||||
|
// add the param format = json to the url or add additional if anothre param is already present
|
||||||
|
if (url.search) {
|
||||||
|
url.search = url.search + '&format=json';
|
||||||
|
} else {
|
||||||
|
url.search = '?format=json';
|
||||||
|
}
|
||||||
|
return handleRequest(url, params, request, fetch, cookies);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @type {import('./$types').RequestHandler} */
|
||||||
|
export async function POST({ url, params, request, fetch, cookies }) {
|
||||||
|
return handleRequest(url, params, request, fetch, cookies, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function PATCH({ url, params, request, fetch, cookies }) {
|
||||||
|
return handleRequest(url, params, request, fetch, cookies, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function PUT({ url, params, request, fetch, cookies }) {
|
||||||
|
return handleRequest(url, params, request, fetch, cookies, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function DELETE({ url, params, request, fetch, cookies }) {
|
||||||
|
return handleRequest(url, params, request, fetch, cookies, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implement other HTTP methods as needed (PUT, DELETE, etc.)
|
||||||
|
|
||||||
|
async function handleRequest(
|
||||||
|
url: any,
|
||||||
|
params: any,
|
||||||
|
request: any,
|
||||||
|
fetch: any,
|
||||||
|
cookies: any,
|
||||||
|
requreTrailingSlash: boolean | undefined = false
|
||||||
|
) {
|
||||||
|
const path = params.path;
|
||||||
|
let targetUrl = `${endpoint}/auth/${path}${url.search}`;
|
||||||
|
|
||||||
|
if (requreTrailingSlash && !targetUrl.endsWith('/')) {
|
||||||
|
targetUrl += '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
const headers = new Headers(request.headers);
|
||||||
|
|
||||||
|
const authCookie = cookies.get('auth');
|
||||||
|
|
||||||
|
if (authCookie) {
|
||||||
|
headers.set('Cookie', `${authCookie}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(targetUrl, {
|
||||||
|
method: request.method,
|
||||||
|
headers: headers,
|
||||||
|
body: request.method !== 'GET' && request.method !== 'HEAD' ? await request.text() : undefined
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.status === 204) {
|
||||||
|
// For 204 No Content, return a response with no body
|
||||||
|
return new Response(null, {
|
||||||
|
status: 204,
|
||||||
|
headers: response.headers
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const responseData = await response.text();
|
||||||
|
|
||||||
|
return new Response(responseData, {
|
||||||
|
status: response.status,
|
||||||
|
headers: response.headers
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error forwarding request:', error);
|
||||||
|
return json({ error: 'Internal Server Error' }, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue