だけkotamats
https://zenn.dev/kotamat/articles/2a63e9958e0905
use ApiSpec\ApiSpecOutput;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use ApiSpecOutput; // 追加
use CreatesApplication;
}
php artisan apispec:aggregate
リクエスト
SPA
DOM生成
表示
サーバ
フロントJS
SSR
サーバ
フロントJS
APIからデータ取得
初回アクセスはSSR、それ以降の画面遷移はSPAになっていくのがNuxtのいいところ
ここの型は共通にしておきたい
今日はここだけ紹介
let counter = 0;
export default (): { counter: number } => {
counter++;
return { counter };
};
/server/api/count.ts
declare module '@nuxt/nitro' {
interface InternalApi {
'/api/count': ReturnType<typeof import('../server/api/count').default>
}
}
export {}
.nuxt/nitro.d.ts
<script lang="ts" setup>
/*
typeof data == Ref<Pick<{
counter: number;
}, "counter">>
*/
const {data} = await useFetch('/api/count')
</script>
app.vue
https://zenn.dev/kotamat/articles/ec36414b696c12
スライドだけ見てる人は下記リポジトリみてみてね
https://github.com/kotamat/nuxt3-laravel
docker run --rm -v "${PWD}:/local" \
openapitools/openapi-generator-cli generate \
-i /local/storage/app/all.json \
-g typescript-axios -o /local/spec
import type { IncomingMessage } from "http";
import { DefaultApi } from "~~/spec";
export default async (req: IncomingMessage) => {
const url = new URL(req.url || "", `http://${req.headers.host}`)
const jobId = url.searchParams.get("job_id") || 0
const api = new DefaultApi()
const { data, status } = await api.apiJobJobGET({
job: +jobId
}, {
validateStatus: status => (status >= 200 && status < 300) || status === 404
})
return { data, status }
}
/server/api/job/show.ts
switch (status) {
case 404:
return { data: data as any as ApiJobJobGETResponse404, status }
default:
return { data, status: status as 200 }
}