Skip to content

How to run http/2 server with Express app? #5108

Description

@khteh
import fs from 'fs';
import { app } from './index.js';
import http2 from 'http2';

const options = {
  key: fs.readFileSync('server.key'),
  cert: fs.readFileSync('server.crt')
};

app.set('port', port);
const server = http2.createSecureServer(options, app);

Error:

server.ts:34:4 - error TS2345: Argument of type 'Express' is not assignable to parameter of type '(request: Http2ServerRequest, response: Http2ServerResponse<Http2ServerRequest>) => void'.
  Types of parameters 'req' and 'request' are incompatible.
    Type 'Http2ServerRequest' is not assignable to type 'IncomingMessage | Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'.
      Type 'Http2ServerRequest' is missing the following properties from type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>': get, header, accepts, acceptsCharsets, and 27 more.

34 }, app);
      ~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions