Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions nuxt/app/composables/useApiFetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const useApiFetch = () => {
const config = useRuntimeConfig()

const apiFetch = $fetch.create({
baseURL: config.public.siteUrl
})

return {
apiFetch
}
}
4 changes: 3 additions & 1 deletion nuxt/app/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<script setup lang="ts">
import type { SlideCard } from '~/types/SlideCard'

const { data: slides } = await useFetch<SlideCard[]>('/api/slides')
const { apiFetch } = useApiFetch()

const slides = await apiFetch<SlideCard[]>(`/slides.json?t=${Date.now()}`)
</script>

<template>
Expand Down
18 changes: 13 additions & 5 deletions nuxt/app/pages/slide-view/[slideId]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ const slideUrl = computed(() => {
return `/slides/${route.params.slideId}/`
})

const { data: slide } = await useFetch<SlideCard>(`/api/slides/${route.params.slideId}`)
const { apiFetch } = useApiFetch()

if (!slide) {
throw createError({ statusCode: 404 })
}
const { data: slide } = await useAsyncData('slide-detail', async () => {
const slides = await apiFetch<SlideCard[]>(`/slides.json?t=${Date.now()}`)

const found: SlideCard | undefined = slides.find((s: SlideCard) => s.id === route.params.slideId)

if (!found) {
throw createError({ statusCode: 404 })
}

return found
})

useHead({
title: slide.value?.title || 'Slide',
Expand All @@ -31,7 +39,7 @@ useHead({
},
{
name: 'og:image',
content: slide.value?.thumbnail ? `${config.public.siteUrl}${slide.value.thumbnail}` : '',
content: slide.value?.thumbnail ? `${config.public.siteUrl}${slide.value?.thumbnail}` : '',
},
{
name: 'twitter:title',
Expand Down
2 changes: 1 addition & 1 deletion nuxt/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
import tailwindcss from '@tailwindcss/vite'

const siteUrl = process.env.NUXT_PUBLIC_SITE_URL || 'https://slides.shade4827.net'
const siteUrl = process.env.NUXT_PUBLIC_SITE_URL || 'http://localhost:3000/'
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

localで叩けないのでlocalhostにした方が良い


export default defineNuxtConfig({
compatibilityDate: '2025-07-15',
Expand Down
8 changes: 0 additions & 8 deletions nuxt/server/api/slides.ts

This file was deleted.

15 changes: 0 additions & 15 deletions nuxt/server/api/slides/[slideId].ts

This file was deleted.