Skip to content
This repository was archived by the owner on Jul 26, 2025. It is now read-only.

Commit 488155a

Browse files
committed
Used new HTTPS API.
1 parent 8690b32 commit 488155a

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

examples/https/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Generate SSL key and certificate using,
2+
3+
openssl genrsa -out privatekey.pem 1024
4+
openssl req -new -key privatekey.pem -out certrequest.csr
5+
openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pem

examples/https/https.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var gh = require('grasshopper'),
2+
fs = require('fs');
3+
4+
gh.secureGet('/', function() {
5+
this.renderText('Secure response!\n');
6+
});
7+
8+
gh.serveSecure(8080, {
9+
key: fs.readFileSync('privatekey.pem'),
10+
cert: fs.readFileSync('certificate.pem')
11+
});

grasshopper/lib/routes.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
exports.api = {};
1818

1919
var http = require('http'),
20+
https = require('https'),
2021
context = require('./context'),
2122
dispatcher = require('./dispatcher'),
2223
RouteMatcher = dispatcher.RouteMatcher;
@@ -101,11 +102,11 @@ function startServer(routes, port, credentials, hostname, callback) {
101102
}
102103

103104
var routeMatcher = new RouteMatcher(routes);
104-
var server = http.createServer();
105-
106105
if(credentials) {
107106
securePort = port;
108-
server.setSecure(credentials);
107+
var server = https.createServer(credentials);
108+
} else {
109+
var server = http.createServer();
109110
}
110111

111112
server.on("request", function(req, res) {

0 commit comments

Comments
 (0)