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

Converting custom-server-fastify to typescript exposes bug #8637

Closed
kobenauf opened this issue Sep 5, 2019 · 4 comments · Fixed by #11040
Closed

Converting custom-server-fastify to typescript exposes bug #8637

kobenauf opened this issue Sep 5, 2019 · 4 comments · Fixed by #11040
Labels
good first issue Easy to fix issues, good for newcomers

Comments

@kobenauf
Copy link

kobenauf commented Sep 5, 2019

Bug report

If examples/custom-server-fastify/server.js is converted to typescript, it exposes a bug in either the next typescript definition for next-server.d.ts or in how server.js is using handleRequest().

Describe the bug

Converting server.js to server.ts reveals a private member access problem on this line:
return app.handleRequest(req.req, reply.res).then(() => {

Here's the error:
Property 'handleRequest' is private and only accessible within class 'Server'.ts(2341)

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Run the instructions in exmaples/custom-server-fastify to create a new project. Specifically,
    npx create-next-app --example custom-server-fastify custom-server-fastify-app
  2. Rename server.js to server.ts.
  3. Fix require/import statements:
import Next from 'next'
import fastifyInit from 'fastify'
const fastify = fastifyInit({ logger: { level: 'error' } })
  1. See error mentioned above.

Expected behavior

Code should not try to use private functions, and there should be no serious typescript errors.

System information

Node 12.8.1
Next 9.0.5

@timneutkens timneutkens added good first issue Easy to fix issues, good for newcomers help wanted labels Sep 6, 2019
@timneutkens
Copy link
Member

Seems like the example is using a private method, it should reflect the custom server api as documented.

@kobenauf
Copy link
Author

kobenauf commented Sep 6, 2019

I converted the lines with the errors to this, and it seems to work. Is this the correct/expected usage in next?
OLD:
return app.handleRequest(req.req, reply.res).then(() => {

NEW:
return app.getRequestHandler()(req.req, reply.res).then(() => {

@timneutkens
Copy link
Member

timneutkens commented Sep 6, 2019

// separate outside of the function
const handle = app.getRequestHandler()

// then usage:
return handle(req.req, reply.res).then(() => {

Not sure from the top of my mind if handle is async or not.

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy to fix issues, good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants