Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working on NextJS app router #614

Open
thienthanit04 opened this issue Jun 24, 2023 · 4 comments
Open

Not working on NextJS app router #614

thienthanit04 opened this issue Jun 24, 2023 · 4 comments

Comments

@thienthanit04
Copy link

I'm using NextJS 13.3.4 for app router and trying to apply this package to my project.
But I got this bellow exception.

  • error Detected default export in '..../api/auth/verify-email/resent/route.ts'. Export a named export for each HTTP method instead.
  • error No HTTP methods exported in '..../api/auth/verify-email/resent/route.ts'. Export a named export for each HTTP method.
@SuperstrongBE
Copy link

SuperstrongBE commented Nov 4, 2023

Exact same error for me
It's seems that the new way Next js structure the API in route and a set of named function (get, post, ... ) doesn't fit the way Next-API-Decorator createHandler works

@SuperstrongBE
Copy link

SuperstrongBE commented Nov 6, 2023

Testing some workaround but lot of classes use NextApiRequest and NextApiResponse instead of the new NextRequest or NextResponse.
Also createHandler should return a set of decorated function or allow more simple process like

import {Body,Post} from 'next-api-decorators'
import { ValidateIdentityDto } from "../../dto/validate-identity.dto";

class IdentityController {

  @Post()
  async validateIdentity(@Body() body: ValidateIdentityDto) {
    console.log(body)
    return Response.json({val:"identity verified",body})
  }
}
// Create the controller 
const controller = new IdentityController();

export async function POST(req: Request, res: Response): Promise<Response> {
  const body = await req.json()
  //Use controller function
  return controller.validateIdentity(body) 
}

The provided code above not working, the @Post decorator throw an error.

Nothing is really usable in app router.
I'm a huge fan of NestJS decorator, allow it in NextJS is game changer, but it needs app router support.
@ggurkal or @leeuwis any roadmap to support app router ?
I've forked the repo, but some part of the code is outside of my skills, maybe team can helps for app router implementation :)

@SuperstrongBE
Copy link

Hello !
I just posted a research around decorator around the new Route handler in NextJS App router to find a possible solution outside this repo and potentially fork and update with the final solution
https://discord.com/channels/752553802359505017/1007476603422527558/threads/1176167694735786096

I also create a gist to make my own research around decorator https://gist.github.com/SuperstrongBE/2d4e6d1aac89797270745f22c9ba047b
Feel free to reach me if you have advices / tips

@g-monroe
Copy link

g-monroe commented Jan 14, 2024

I was also working on this, as having a robust easy routing through classes and decorators is a must for me. So even here my attempt with reference to @SuperstrongBE inspirations. Still working on it, but got path routing down, with args being passed down.
https://gist.github.com/g-monroe/307005780ec0c63854598ef9bf3771d0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants