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 pages+Next.jsの環境でServerActionsを実行すると405が返ってくる件について

Posted at

はじめに

今回、新サービスを開発するにあたりLPのコストをできるだけ抑えようと思った結果、以下のスタックで開発することにした。

Next.js
フロントエンドの実装
Supabase
WaitinglistのDBやストレージ
v0
LPのUIデザイン
Cloudflare pages
本番/ステージング環境

このスタックを用いて開発した結果費用は¥0となりコスト削減は達成できたが、問題が発生した。

ServerActionsが動かねぇ!!!

問題

本来であれば

の順にデータ処理を行いSupabaseにデータを格納したかったのだが、
ServerActionsを叩いたときに405 method not allowedが返された。

考察

どうもNext.js v13の時は問題ないようなのだが、v14以降でServerActionsが動かなくなってるらしい。
ましてや今回はv15のAppRouterを使っているので諦めようとした。

解決策

ServerActionsではなくAPIRoutesを使う

つまり、ServerActionsだと静的ページにPOSTを送るためなんらかの制限がかかっているが、APIRoutesは普通に処理ができるらしいので今回は

の流れで処理を行った。

結果

最高の環境でいいLPができました(¥0で)
作ったLPはコチラ↓

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?