目的:templateサイトの構成を読み込む

以下を実行した。

npm create cloudflare@latest -- --template=cloudflare/templates/chanfana-openapi-template

参考URL https://dash.cloudflare.com/89293ce1d40b4a996dc0598e26a1be23/workers/services/view/recipist/production/metrics

ここでできた成果物を読み込んでみる。

読んでみた結果

  • index.ts
    • エンドポイント。メイン関数みたいなもの
  • endpoints
    • endpointsを示してる。このディレクトリ構成がpathの構成を示すように管理されている。
    • endpoints/tasks
      • タスク管理用のエンドポイントが配置されている。
      • router.ts
        • chanfanaとHonoの接続はここで行われる。 fromHono はRouter定義関数 tasksRouter を返す。
        • taskCreate.ts等によって作られたエンドポイントの実態をrouter (tasksRouter)と接続する。
      • taskCreate.ts
        • tasksRouterに引き渡す処理の実態を記入する
          • 単純なものは chanfana の D1{Read|Create|Update|etc}Endpoint で定義を書くだけで実現できる。
      • etc
        • そのほかtaskに関する処理を記載しておく。