0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Cloudflare Workers 静的アセット使用時のルーティング動作

Posted at

公式ドキュメント

デフォルトでは以下

  1. リクエストされたURLに該当するアセットがあれば返す
  2. ない場合で、ワーカーがあればワーカー起動
  3. ただし not_found_handling = "single-page-application" が設定されていれば、Workerは起動せず index.html が返る (SPAのルーティングを動作させるため)

SSRではないReactとHonoのAPIではブラウザでアクセスした際、先にReactが見られてしまう

image.png
image.png

run_worker_firstにWorkerを優先したいエンドポイントを指定できる
(無くても React から Hono へのリクエストは動作してました)

wrangler.jsonc
"assets": {
    "not_found_handling": "single-page-application",
    "run_worker_first": ["/api/*"], // これを追加
},

image.png

OpenAPI + swaggerUI を採用する際に使用できそうです

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?