Permalink
Browse files

Used new HTTPS API.

  • Loading branch information...
1 parent 8690b32 commit 488155adae4307c98d799c8f7313536ebe8b2585 @cskr committed Jan 28, 2011
Showing with 20 additions and 3 deletions.
  1. +5 −0 examples/https/README.md
  2. +11 −0 examples/https/https.js
  3. +4 −3 grasshopper/lib/routes.js
View
@@ -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
View
@@ -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')
+});
@@ -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) {

0 comments on commit 488155a

Please sign in to comment.