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

with-http2 example exposes problems when converted to typescript #8625

Closed
kobenauf opened this issue Sep 4, 2019 · 6 comments
Closed

with-http2 example exposes problems when converted to typescript #8625

kobenauf opened this issue Sep 4, 2019 · 6 comments
Labels
good first issue Easy to fix issues, good for newcomers

Comments

@kobenauf
Copy link

kobenauf commented Sep 4, 2019

Bug report

Describe the bug

Using the with-http2 example, and then converting server.js to server.ts, the following line has two problems:
return app.render(req, res, '/about', req.query)

Error 1:

Argument of type 'Http2ServerRequest' is not assignable to parameter of type 'IncomingMessage'.
  Type 'Http2ServerRequest' is missing the following properties from type 'IncomingMessage': httpVersionMajor, httpVersionMinor, complete, connectionts(2345)

Error 2:
Property 'query' does not exist on type 'Http2ServerRequest'.ts(2339)

To Reproduce

Create a new project following instructions at with-http2:

  1. npx create-next-app --example with-http2 my-app
  2. Rename server.js to server.ts.
  3. Optional: convert the require statements to import statements.
  4. See ts errors listed above.

Expected behavior

The with-http2 probably has some bugs that are not visible until being converted to typescript. The idea of with-http2 is useful, and ideally there would be an http2 template like this.

System information

Node 12.8.0

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

Error1, I might be need that render() support http2 types. like this

req: IncomingMessage | Http2ServerRequest,
res: ServerResponse | Http2ServerResponse,

Error2, using querystring

const parsedUrl = querystring.parse(req.url);

@kobenauf
Copy link
Author

kobenauf commented Sep 5, 2019

I made these changes:

import http2, { Http2ServerRequest, Http2ServerResponse } from 'http2'
import { IncomingMessage, ServerResponse } from 'http'
import querystring from 'querystring'
  server.on('request', (req: IncomingMessage | Http2ServerRequest, res: ServerResponse | Http2ServerResponse) => {
    switch (req.url) {
      case '/about':
        return app.render(req, res, '/about', querystring.parse(req.url))
      default:
        return app.render(req, res, '/', querystring.parse(req.url))
    }
  })

The second error is fixed now, but the first error is still there, with a different message now but same underlying problem:

Argument of type 'IncomingMessage | Http2ServerRequest' is not assignable to parameter of type 'IncomingMessage'.
  Type 'Http2ServerRequest' is missing the following properties from type 'IncomingMessage': httpVersionMajor, httpVersionMinor, complete, connectionts(2345)

@kobenauf
Copy link
Author

kobenauf commented Sep 5, 2019

I suspect this issue might be related to underlying problems in how Express implements http vs http2 request abstractions:
expressjs/express#3390
expressjs/express#3730

@ragingwind
Copy link
Contributor

for 1 issues, next-server.d.ts might be changed to

render(
    req: IncomingMessage | Http2ServerRequest,
    res: ServerResponse | Http2ServerResponse,
    pathname: string,
    query?: ParsedUrlQuery,
    parsedUrl?: UrlWithParsedQuery
  ): Promise<void>;

but I'm not sure it is the best solution

@balazsorban44
Copy link
Member

balazsorban44 commented Jan 12, 2022

We now take PRs to convert existing examples to TS, but with-http2 is an exception, as custom servers are discouraged and thus we are not prioritizing work on them.

Before deciding to use a custom server, please keep in mind that it should only be used when the integrated router of Next.js can't meet your app requirements. A custom server will remove important performance optimizations, like serverless functions and Automatic Static Optimization.

https://nextjs.org/docs/advanced-features/custom-server

Since the example is working as expected in its current form, I'm closing this issue.

UPDATE: nodejs/help#4253 (comment)

@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 Feb 11, 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

No branches or pull requests

5 participants