{"id":13802839,"url":"https://github.com/mscdex/httpolyglot","last_synced_at":"2025-04-12T23:42:16.237Z","repository":{"id":18675117,"uuid":"21883652","full_name":"mscdex/httpolyglot","owner":"mscdex","description":"Serve http and https connections over the same port with node.js","archived":false,"fork":false,"pushed_at":"2019-05-15T13:59:04.000Z","size":14,"stargazers_count":181,"open_issues_count":4,"forks_count":14,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-12T23:42:11.766Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/mscdex.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":"2014-07-16T02:32:13.000Z","updated_at":"2024-08-27T01:09:28.000Z","dependencies_parsed_at":"2022-09-26T21:51:08.623Z","dependency_job_id":null,"html_url":"https://github.com/mscdex/httpolyglot","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fhttpolyglot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fhttpolyglot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fhttpolyglot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fhttpolyglot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mscdex","download_url":"https://codeload.github.com/mscdex/httpolyglot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647257,"owners_count":21139081,"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":[],"created_at":"2024-08-04T00:01:59.862Z","updated_at":"2025-04-12T23:42:16.213Z","avatar_url":"https://github.com/mscdex.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\nDescription\n===========\n\nA module for serving http and https connections over the same port.\n\n\nRequirements\n============\n\n* [node.js](http://nodejs.org/) -- v0.10.0 or newer\n\n\nInstall\n============\n\n    npm install httpolyglot\n\n\nExamples\n========\n\n* Simple usage:\n\n```javascript\nvar httpolyglot = require('httpolyglot');\nvar fs = require('fs');\n\nhttpolyglot.createServer({\n  key: fs.readFileSync('server.key'),\n  cert: fs.readFileSync('server.crt')\n}, function(req, res) {\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end((req.socket.encrypted ? 'HTTPS' : 'HTTP') + ' Connection!');\n}).listen(9000, 'localhost', function() {\n  console.log('httpolyglot server listening on port 9000');\n  // visit http://localhost:9000 and https://localhost:9000 in your browser ...\n});\n```\n\n* Simple redirect of all http connections to https:\n\n```javascript\nvar httpolyglot = require('httpolyglot');\nvar fs = require('fs');\n\nhttpolyglot.createServer({\n  key: fs.readFileSync('server.key'),\n  cert: fs.readFileSync('server.crt')\n}, function(req, res) {\n  if (!req.socket.encrypted) {\n    res.writeHead(301, { 'Location': 'https://localhost:9000' });\n    return res.end();\n  }\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end('Welcome, HTTPS user!');\n}).listen(9000, 'localhost', function() {\n  console.log('httpolyglot server listening on port 9000');\n  // visit http://localhost:9000 and https://localhost:9000 in your browser ...\n});\n```\n\n\nAPI\n===\n\nExports\n-------\n\n* **Server** - A class similar to https.Server (except instances have `setTimeout()` from http.Server).\n\n* **createServer**(\u003c _object_ \u003etlsConfig[, \u003c _function_ \u003erequestListener]) - _Server_ - Creates and returns a new Server instance.\n\nHow it Works\n============\n\nTLS and HTTP connections are easy to distinguish based on the first byte sent by clients trying to connect. See [this comment](https://github.com/mscdex/httpolyglot/issues/3#issuecomment-173680155) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmscdex%2Fhttpolyglot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmscdex%2Fhttpolyglot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmscdex%2Fhttpolyglot/lists"}