{"id":15771656,"url":"https://github.com/nwtgck/http2-http1-server-node","last_synced_at":"2026-01-21T16:32:03.905Z","repository":{"id":48452714,"uuid":"177373892","full_name":"nwtgck/http2-http1-server-node","owner":"nwtgck","description":"HTTP/2-interface HTTP1 server for compatibility for Node.js/TypeScript","archived":false,"fork":false,"pushed_at":"2021-07-25T16:46:28.000Z","size":288,"stargazers_count":2,"open_issues_count":11,"forks_count":0,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2024-10-11T15:10:49.174Z","etag":null,"topics":["http-server","http1","http1-1","http2","node","nodejs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nwtgck.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-24T05:18:12.000Z","updated_at":"2020-05-20T07:04:11.000Z","dependencies_parsed_at":"2022-09-08T02:36:28.248Z","dependency_job_id":null,"html_url":"https://github.com/nwtgck/http2-http1-server-node","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nwtgck%2Fhttp2-http1-server-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nwtgck%2Fhttp2-http1-server-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nwtgck%2Fhttp2-http1-server-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nwtgck%2Fhttp2-http1-server-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nwtgck","download_url":"https://codeload.github.com/nwtgck/http2-http1-server-node/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247623011,"owners_count":20968574,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http-server","http1","http1-1","http2","node","nodejs"],"created_at":"2024-10-04T15:03:59.242Z","updated_at":"2026-01-21T16:32:03.186Z","avatar_url":"https://github.com/nwtgck.png","language":"TypeScript","readme":"# http2-http1-server\n[![CircleCI](https://circleci.com/gh/nwtgck/http2-http1-server-node.svg?style=shield)](https://circleci.com/gh/nwtgck/http2-http1-server-node)\n\nHTTP/2-interface HTTP1 server for compatibility for Node.js/TypeScript\n\n## Purpose\n\nThe purpose of this project is for compatibility to support HTTP/1 clients over non-TLS in Node.js/TypeScript.\n\nUnfortunately [current type definitions](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/a642ee239c2992dd1ca45a1a0baeaa4169f374cd) of [HTTP/2 Compatible API](https://nodejs.org/api/http2.html#http2_compatibility_api) is not compatible like the following. The handler types are different.\n\n```ts\n// http\nfunction createServer(options: ServerOptions, requestListener?: (req: IncomingMessage, res: ServerResponse) =\u003e void): Server;\n```\n\n```ts\n// http2\nexport function createServer(options: ServerOptions, onRequestHandler?: (request: Http2ServerRequest, response: Http2ServerResponse) =\u003e void): Http2Server;\n```\n\nSo, Node.js developers in TypeScript should **implement two different types of handlers** to support both HTTP/1 and HTTP/2 over non-TLS.\nTo solve the annoying issue, this project provides HTTP/1 server whose interface is the same as `http2.createServer()`. This project allows you to implement only one handler(= `(request: Http2ServerRequest, response: Http2ServerResponse) =\u003e void`).\n\n## Installation\n\n```bash\nnpm install -S git+https://github.com/nwtgck/http2-http1-server-node\n```\n\n## Usage\n\nHere is an example to use.\n\n```ts\nimport { createServer } from \"http2-http1-server\";\nimport * as http2 from \"http2\";\nimport { readFileSync } from \"fs\";\n\nconst cert = readFileSync('./ssl_certs/server.crt');\nconst key  = readFileSync('./ssl_certs/server.key');\n\nconst handler = (req: http2.Http2ServerRequest, res: http2.Http2ServerResponse) =\u003e {\n  res.end(\"hello from server!\");\n};\n\n// [IMPORTANT] You can use the same handler!\nconst server       = createServer({}, handler);\nconst secureServer = http2.createSecureServer({cert, key}, handler);\n\nserver.listen(8080);\nsecureServer.listen(8443);\n```\n\n* `server` supports only HTTP/1.\n* `secureServer` supports both HTTP/1 and HTTP/2 because it uses [ALPN](https://nodejs.org/api/http2.html#http2_alpn_negotiation).\n\nYou can find whole example in [examples/simple](examples/simple).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnwtgck%2Fhttp2-http1-server-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnwtgck%2Fhttp2-http1-server-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnwtgck%2Fhttp2-http1-server-node/lists"}