diff --git a/src/app.d.ts b/src/app.d.ts index a061326..ff6fafd 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -1,6 +1,6 @@ // See https://svelte.dev/docs/kit/types#app.d.ts -import type { Strapi } from "$lib/server/strapi"; +import type { Strapi } from '$lib/server/strapi'; // for information about these interfaces declare global { diff --git a/src/hooks.server.ts b/src/hooks.server.ts index aa44e2a..08c17a9 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -1,30 +1,22 @@ -import { env } from "$env/dynamic/private"; -import { Strapi } from "$lib/server/strapi"; -import type { Handle, HandleServerError } from "@sveltejs/kit"; -import { randomUUID } from "crypto"; +import { env } from '$env/dynamic/private'; +import { Strapi } from '$lib/server/strapi'; +import type { Handle, HandleServerError } from '@sveltejs/kit'; +import { randomUUID } from 'crypto'; -export const handleError: HandleServerError = async ({ - error, - event, - message, - status, -}) => { +export const handleError: HandleServerError = async ({ error, event, message, status }) => { const errorId = randomUUID(); console.error(error, { errorId, event, message, status }); return { - message: "An Internal Error Occurred", - errorId, + message: 'An Internal Error Occurred', + errorId }; }; export const handle: Handle = async ({ event, resolve }) => { event.locals = { - strapi: new Strapi( - `http://${env.STRAPI_HOST}:${env.STRAPI_PORT}`, - env.STRAPI_TOKEN, - ), + strapi: new Strapi(`http://${env.STRAPI_HOST}:${env.STRAPI_PORT}`, env.STRAPI_TOKEN) }; const response = await resolve(event); diff --git a/src/lib/server/strapi/index.ts b/src/lib/server/strapi/index.ts index 175b98c..a42303c 100644 --- a/src/lib/server/strapi/index.ts +++ b/src/lib/server/strapi/index.ts @@ -1,31 +1,33 @@ -import { strapi, type StrapiClient } from "@strapi/client"; +import { strapi, type StrapiClient } from '@strapi/client'; export class Strapi { + public readonly api: string; + public readonly uploads: string; + private readonly client: StrapiClient; - constructor( - public readonly url: string, - auth: string, - ) { + constructor(url: string, auth: string) { + this.api = `${url}/api`; + this.uploads = `${url}/uploads`; this.client = strapi({ - baseURL: `${url}/api`, - auth: auth, + baseURL: this.api, + auth: auth }); } async Blogs() { - const blogs = this.client.collection("blogs"); + const blogs = this.client.collection('blogs'); return await blogs.find({ - populate: ["Header", "Topics"], + populate: ['Header', 'Topics'] }); } async Blog(id: string) { - const blogs = this.client.collection("blogs"); + const blogs = this.client.collection('blogs'); return await blogs.findOne(id, { - populate: ["Header", "Topics"], + populate: ['Header', 'Topics'] }); } } diff --git a/src/routes/blog/+page.server.ts b/src/routes/blog/+page.server.ts index 1f8f73a..fe5d3ae 100644 --- a/src/routes/blog/+page.server.ts +++ b/src/routes/blog/+page.server.ts @@ -1,5 +1,5 @@ -import { error } from "@sveltejs/kit"; -import type { PageServerLoad } from "./$types"; +import { error } from '@sveltejs/kit'; +import type { PageServerLoad } from './$types'; export const load: PageServerLoad = async ({ locals }) => { const { strapi } = locals; @@ -12,20 +12,20 @@ export const load: PageServerLoad = async ({ locals }) => { id: post.documentId, image: { url: post.Header.formats.medium.url, - alt: post.Header.alternativeText, + alt: post.Header.alternativeText }, title: post.Title, body: post.Body, topics: post.Topics.map((topic: { id: string; Topic: string }) => ({ id: topic.id, - name: topic.Topic, + name: topic.Topic })), - published: post.publishedAt, + published: post.publishedAt })), - meta, + meta }; } catch (err) { - console.log("Uh-oh!"); + console.log('Uh-oh!'); error(500, err.message); } }; diff --git a/src/routes/blog/+page.svelte b/src/routes/blog/+page.svelte index 13b82b3..4f4902e 100644 --- a/src/routes/blog/+page.svelte +++ b/src/routes/blog/+page.svelte @@ -1,5 +1,4 @@