From 488155adae4307c98d799c8f7313536ebe8b2585 Mon Sep 17 00:00:00 2001 From: Chandra Sekar S Date: Fri, 28 Jan 2011 19:11:53 +0530 Subject: [PATCH] Used new HTTPS API. --- examples/https/README.md | 5 +++++ examples/https/https.js | 11 +++++++++++ grasshopper/lib/routes.js | 7 ++++--- 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 examples/https/README.md create mode 100644 examples/https/https.js diff --git a/examples/https/README.md b/examples/https/README.md new file mode 100644 index 0000000..f1e070f --- /dev/null +++ b/examples/https/README.md @@ -0,0 +1,5 @@ +Generate SSL key and certificate using, + + openssl genrsa -out privatekey.pem 1024 + openssl req -new -key privatekey.pem -out certrequest.csr + openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pem diff --git a/examples/https/https.js b/examples/https/https.js new file mode 100644 index 0000000..c0697bf --- /dev/null +++ b/examples/https/https.js @@ -0,0 +1,11 @@ +var gh = require('grasshopper'), + fs = require('fs'); + +gh.secureGet('/', function() { + this.renderText('Secure response!\n'); +}); + +gh.serveSecure(8080, { + key: fs.readFileSync('privatekey.pem'), + cert: fs.readFileSync('certificate.pem') +}); diff --git a/grasshopper/lib/routes.js b/grasshopper/lib/routes.js index dd9e3b7..2d309fb 100644 --- a/grasshopper/lib/routes.js +++ b/grasshopper/lib/routes.js @@ -17,6 +17,7 @@ exports.api = {}; var http = require('http'), + https = require('https'), context = require('./context'), dispatcher = require('./dispatcher'), RouteMatcher = dispatcher.RouteMatcher; @@ -101,11 +102,11 @@ function startServer(routes, port, credentials, hostname, callback) { } var routeMatcher = new RouteMatcher(routes); - var server = http.createServer(); - if(credentials) { securePort = port; - server.setSecure(credentials); + var server = https.createServer(credentials); + } else { + var server = http.createServer(); } server.on("request", function(req, res) {