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?

vercelにデプロイしたAPIにPOSTできない

Posted at

発生した問題

以下のファイルを含んだNext.jsのプロジェクトをvercelにデプロイした。

./src/app/api/route.ts
import { NextRequest, NextResponse } from "next/server";

export async function POST(request: NextRequest) {
  const body = await request.json();
  console.log(body);
  
  return NextResponse.json(
    { message: "POST test" });
}

ここにPOSTしようとすると405 Method Not Allowedが返されてしまう。

解決方法

1. next.config.mjsoutput: "export"を削除する

next.config.mjs
const nextConfig = {
    // output: "export",
};

2. vercelにデプロイする

console
vercel
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?