Skip to content

Commit

Permalink
Used new HTTPS API.
Browse files Browse the repository at this point in the history
  • Loading branch information
cskr committed Jan 28, 2011
1 parent 8690b32 commit 488155a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions examples/https/README.md
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions examples/https/https.js
Original file line number Diff line number Diff line change
@@ -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')
});
7 changes: 4 additions & 3 deletions grasshopper/lib/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
exports.api = {};

var http = require('http'),
https = require('https'),
context = require('./context'),
dispatcher = require('./dispatcher'),
RouteMatcher = dispatcher.RouteMatcher;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 488155a

Please sign in to comment.