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

Usage with next-routes #39

Open
webberwang opened this issue Feb 3, 2020 · 3 comments
Open

Usage with next-routes #39

webberwang opened this issue Feb 3, 2020 · 3 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@webberwang
Copy link

webberwang commented Feb 3, 2020

The controller stops working if I use the routes handler.

codelab-ui-nestjs____Code_UIB_codelab-ui-nestjs__-_____packages_core_server_server_ts

codelab-ui-nestjs____Code_UIB_codelab-ui-nestjs__-_____packages_core_server_app_app_controller_ts

I'm also unable to access useRouter().query from next/router if I'm using routing with controller

@webberwang webberwang reopened this Feb 3, 2020
@kyle-mccarthy
Copy link
Owner

kyle-mccarthy commented Feb 3, 2020 via email

@webberwang
Copy link
Author

webberwang commented Feb 3, 2020

@kyle-mccarthy

useRouter is just empty object, which is inline with Nest not passing requests to Next.

Right, solving issue 2 (resolving requests not resolved in nest) would solve 1 (external router not working), since we wouldn't need next-routes anymore.

Here's my attempt following #38...

server.ts

@Catch(NotFoundException)
export class NextPageFilter implements ExceptionFilter {
  private requestHandler?: RequestHandler;

  constructor(@Inject() private readonly renderService: RenderService) {
    this.requestHandler = this.renderService.getRequestHandler();
  }

  catch(exception: HttpException, host: ArgumentsHost) {
    const ctx = host.switchToHttp();
    const res = ctx.getResponse();
    const req = ctx.getRequest();

    if (this.requestHandler) {
      return this.requestHandler(req, res);
    }

    throw exception;
  }
}

(async () => {
  /**
   * Create server
   */
  const server = Server({
    dev: true,
  });
  await server.prepare();

  /**
   * Create app
   */
  const app = await NestFactory.create(AppModule);

  const renderer = app.get(RenderModule);
  renderer.register(app as any, server);

  /**
   * Add service
   */
  const service = app.get(RenderService);
  app.useGlobalFilters(new NextPageFilter(service));

  await app.listen(3000);
})();

useRouter is still showing blank. I'm not too sure how to pass requests that don’t resolve within nest and try to resolve the request with next. There isn't too much info on the internet for this specific use case.

@kyle-mccarthy kyle-mccarthy added the enhancement New feature or request label May 11, 2020
@kyle-mccarthy
Copy link
Owner

@webberwang I added a new option in the nest-next beta preview. I think that it may allow for you to use next-routes. See #38 (comment)

@kyle-mccarthy kyle-mccarthy added the question Further information is requested label Sep 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants