[▲ Vercel Community](/) · [Categories](/categories) · [Latest](/latest) · [Top](/top) · [Live](/live)

[Help](/c/help/9)

# 405 Method Disallowed for POST on Vercel

483 views · 0 likes · 2 posts


Jakkaps (@jakkaps) · 2024-08-08

I am getting a 405 Method disallowed when trying to make POST requests on my production app. The POST request is working fine locally.

This is my `api/backend/[...request]`:

```typescript
import { getAccessToken } from '@auth0/nextjs-auth0';
import { NextRequest } from 'next/server';

const BACKEND_URL = process.env.NEXT_PUBLIC_BACKEND_URL;

async function prepareHeaders() {
    const { accessToken } = await getAccessToken();

    return {
        access_token: accessToken || '',
    };
}

async function prepareUrl(req: NextRequest) {
    const path = req.url && req.url.split('/api/backend')[1];
    return `${BACKEND_URL}${path}`;
}

export async function GET(req: NextRequest) {
    const headers = await prepareHeaders();
    const url = await prepareUrl(req);

    return await fetch(url, {
        method: 'GET',
        headers: headers,
    }).catch((e) => {
        console.error(e);
        return new Response('Internal Server Error', { status: 500 });
    });
}

export async function POST(req: NextRequest, res: Response) {
    const headers = await prepareHeaders();
    const url = await prepareUrl(req);

    let body = {};
    try {
        body = await req.json();
    } catch (e) {
        console.error(e);
        return new Response('Invalid JSON', { status: 400 });
    }

    return await fetch(url, {
        method: 'POST',
        headers: { ...headers, 'Content-Type': 'application/json' },
        body: JSON.stringify(body),
    });
}
```


Pauline P. Narvas (@pawlean) · 2024-08-08

Hi, @jakkaps!

Re-posting a similar topic:

https://community.vercel.com/t/405-method-not-allowed-on-post-api-in-vercel-production-works-fine-locally/373