{"id":26347306,"url":"https://github.com/survi218/https-secure-server","last_synced_at":"2025-07-31T06:14:15.896Z","repository":{"id":139643135,"uuid":"93797130","full_name":"survi218/https-secure-server","owner":"survi218","description":"Redirect traffic from the insecure HTTP server to a secure HTTPS server","archived":false,"fork":false,"pushed_at":"2017-06-08T23:25:56.000Z","size":4069,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-16T07:16:29.964Z","etag":null,"topics":["cryptography","https","https-server","openssl","private-key","redirecting-requests","secure","secure-communication","tls-certificate"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/survi218.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-08T22:34:45.000Z","updated_at":"2017-06-08T23:31:24.000Z","dependencies_parsed_at":"2023-07-23T08:01:51.704Z","dependency_job_id":null,"html_url":"https://github.com/survi218/https-secure-server","commit_stats":null,"previous_names":["survi218/https-secure-server"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/survi218/https-secure-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/survi218%2Fhttps-secure-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/survi218%2Fhttps-secure-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/survi218%2Fhttps-secure-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/survi218%2Fhttps-secure-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/survi218","download_url":"https://codeload.github.com/survi218/https-secure-server/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/survi218%2Fhttps-secure-server/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267997183,"owners_count":24178251,"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","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cryptography","https","https-server","openssl","private-key","redirecting-requests","secure","secure-communication","tls-certificate"],"created_at":"2025-03-16T07:16:34.561Z","updated_at":"2025-07-31T06:14:15.853Z","avatar_url":"https://github.com/survi218.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# https-secure-server\n* Exploring the use of the HTTPS server core node module to create and run a secure       server and generating your private key and public certificate and use them to           configure the Node HTTPS server.\n  - Configure a secure server in Node using the core HTTPS module\n  - Generate the private key and public certificate and configure the HTTPS server\n  - Redirect traffic from the insecure HTTP server to a secure HTTPS server.\n# Updating the bin/www File\n- Open the www file in the bin directory and update its contents as follows:\n\n````\n#!/usr/bin/env node\n/**\n * Module dependencies.\n */\n\nvar app = require('../app');\nvar debug = require('debug')('rest-server:server');\nvar http = require('http');\nvar https = require('https');\nvar fs = require('fs');\n\n/**\n * Get port from environment and store in Express.\n */\n\nvar port = normalizePort(process.env.PORT || '3000');\n\napp.set('port', port);\napp.set('secPort',port+443);\n\n/**\n * Create HTTP server.\n */\n\nvar server = http.createServer(app);\n\n/**\n * Listen on provided port, on all network interfaces.\n */\n\nserver.listen(port, function() {\n   console.log('Server listening on port ',port);\n});\nserver.on('error', onError);\nserver.on('listening', onListening);\n\n/**\n * Create HTTPS server.\n */ var options = {\n  key: fs.readFileSync(__dirname+'/private.key'),\n  cert: fs.readFileSync(__dirname+'/certificate.pem')\n};\n\nvar secureServer = https.createServer(options,app);\n\n/**\n * Listen on provided port, on all network interfaces.\n */\n\nsecureServer.listen(app.get('secPort'), function() {\n   console.log('Server listening on port ',app.get('secPort'));\n});\nsecureServer.on('error', onError);\nsecureServer.on('listening', onListening);\n\n/**\n * Normalize a port into a number, string, or false.\n */\n\nfunction normalizePort(val) {\n  var port = parseInt(val, 10);\n  if (isNaN(port)) {\n    // named pipe\n    return val;\n  }\n  if (port \u003e= 0) {\n    // port number\n    return port;\n  }\n  return false;\n}\n\n/**\n * Event listener for HTTP server \"error\" event.\n */\n\nfunction onError(error) {\n  if (error.syscall !== 'listen') {\n    throw error;\n  }\n  var bind = typeof port === 'string'\n    ? 'Pipe ' + port\n    : 'Port ' + port;\n\n  // handle specific listen errors with friendly messages\n  switch (error.code) {\n    case 'EACCES':\n      console.error(bind + ' requires elevated privileges');\n      process.exit(1);\n      break;\n\n    case 'EADDRINUSE':\n      console.error(bind + ' is already in use');\n      process.exit(1);\n      break;\n\n    default:\n      throw error;\n  }\n}\n\n/**\n * Event listener for HTTP server \"listening\" event.\n */\n\nfunction onListening() {\n  var addr = server.address();\n  var bind = typeof addr === 'string'\n    ? 'pipe ' + addr\n    : 'port ' + addr.port;\n  debug('Listening on ' + bind);\n}\n````\n\n- Updating app.js\n- Open app.js and add the following code to the file:\n\n````\n// Secure traffic only\napp.all('*', function(req, res, next){\n    console.log('req start: ',req.secure, req.hostname, req.url, app.get('port'\n      ));\n  if (req.secure) {\n    return next();\n  };\n\n res.redirect('https://'+req.hostname+':'+app.get('secPort')+req.url);\n});\n````\n# Generating Private Key and Certificate\n* Go to the bin folder and then create the private key and certificate by typing the      following at the prompt:\n````\nopenssl genrsa 1024 \u003e private.key\nopenssl req -new -key private.key -out cert.csr\nopenssl x509 -req -in cert.csr -signkey private.key -out certificate.pem\n````\nRun the server and test.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsurvi218%2Fhttps-secure-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsurvi218%2Fhttps-secure-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsurvi218%2Fhttps-secure-server/lists"}