ts-rest / ts-rest

RPC-like client, contract, and server implementation for a pure REST API
https://ts-rest.com
MIT License
2.11k stars 91 forks source link

serverless/next: Return 405 Method Not Allowed for methods that are not being implemented #612

Open digitex opened 1 week ago

digitex commented 1 week ago

For Next.js with App Router, any unimplemented methods will return 404 instead of 405:

Taking example from https://github.com/ts-rest/ts-rest/blob/main/apps/example-next/

import { initContract } from '@ts-rest/core';
import { z } from 'zod';

const c = initContract();

export const testContract = c.router(
  {
    test: {
      method: 'GET',
      path: '/test/:id',
      pathParams: z.object({
        id: z.coerce.number(),
      }),
      query: z.object({
        foo: z.string(),
        bar: z.number(),
      }),
      responses: {
        200: z.object({
          id: z.number(),
          foo: z.string(),
          bar: z.number(),
        }),
      },
    },
  },
  {
    strictStatusCodes: true,
  },
);

POST request to /test/:id will return HTTP 404:

{
  "message": "Not Found"
}