Skip to content
Browse files

Set up example servers to run in HTTPS mode.

  • Loading branch information...
1 parent 1784136 commit 35e6d75c66b2e14ffcccf636983dabfe6a3360a3 @jcoglan jcoglan committed
Showing with 67 additions and 13 deletions.
  1. +2 −2 Rakefile
  2. +23 −9 examples/node/server.js
  3. +12 −2 examples/ruby/server.rb
  4. +15 −0 examples/shared/server.crt
  5. +15 −0 examples/shared/server.key
View
4 Rakefile
@@ -1,8 +1,8 @@
require 'rubygems'
require './lib/faye'
-task :example, :port do |t, args|
- exec "ruby examples/ruby/server.rb #{args[:port]}"
+task :example, :port, :ssl do |t, args|
+ exec "ruby examples/ruby/server.rb #{args[:port]} #{args[:ssl] && 'ssl'}"
end
task :handshake, :port, :n, :c do |t, args|
View
32 examples/node/server.js
@@ -1,30 +1,44 @@
var fs = require('fs'),
path = require('path'),
http = require('http'),
+ https = require('https'),
faye = require('../../build/faye-node');
// faye.Logging.logLevel = 'debug';
-var PUBLIC_DIR = path.dirname(__filename) + '/../shared/public',
+var SHARED_DIR = path.dirname(__filename) + '/../shared',
+ PUBLIC_DIR = SHARED_DIR + '/public',
+
bayeux = new faye.NodeAdapter({mount: '/bayeux', timeout: 20}),
- port = process.ARGV[2] || '8000';
+ port = process.ARGV[2] || '8000',
+ secure = process.ARGV[3] === 'ssl',
+
+ sslOpts = {
+ key: fs.readFileSync(SHARED_DIR + '/server.key'),
+ cert: fs.readFileSync(SHARED_DIR + '/server.crt')
+ };
-bayeux.getClient().subscribe('/chat/*', function(message) {
- console.log('[' + message.user + ']: ' + message.message);
-});
-
-var server = http.createServer(function(request, response) {
+var handleRequest = function(request, response) {
var path = (request.url === '/') ? '/index.html' : request.url;
+
fs.readFile(PUBLIC_DIR + path, function(err, content) {
var status = err ? 404 : 200;
response.writeHead(status, {'Content-Type': 'text/html'});
response.write(content || 'Not found');
response.end();
});
-});
+};
+
+var server = secure
+ ? https.createServer(sslOpts, handleRequest)
+ : http.createServer(handleRequest);
bayeux.attach(server);
server.listen(Number(port));
-console.log('Listening on ' + port);
+bayeux.getClient().subscribe('/chat/*', function(message) {
+ console.log('[' + message.user + ']: ' + message.message);
+});
+
+console.log('Listening on ' + port + (secure? ' (https)' : ''));
View
14 examples/ruby/server.rb
@@ -12,11 +12,21 @@
:engine => {:type => 'redis'}
)
-port = ARGV[0] || 9292
+port = ARGV[0] || 9292
+secure = ARGV[1] == 'ssl'
EM.run {
thin = Rack::Handler.get('thin')
- thin.run(server, :Port => port)
+ thin.run(server, :Port => port) do |s|
+
+ if secure
+ s.ssl = true
+ s.ssl_options = {
+ :private_key_file => dir + '/../shared/server.key',
+ :cert_chain_file => dir + '/../shared/server.crt'
+ }
+ end
+ end
server.get_client.subscribe '/chat/*' do |message|
puts "[#{ message['user'] }]: #{ message['message'] }"
View
15 examples/shared/server.crt
@@ -0,0 +1,15 @@
+-----BEGIN CERTIFICATE-----
+MIICZTCCAc4CCQDxyrJZrFA0vjANBgkqhkiG9w0BAQUFADB3MQswCQYDVQQGEwJV
+SzEPMA0GA1UECBMGTG9uZG9uMQ8wDQYDVQQHEwZMb25kb24xDTALBgNVBAoTBEZh
+eWUxFTATBgNVBAMTDEphbWVzIENvZ2xhbjEgMB4GCSqGSIb3DQEJARYRamNvZ2xh
+bkBnbWFpbC5jb20wHhcNMTEwODMwMTIzOTM2WhcNMTIwODI5MTIzOTM2WjB3MQsw
+CQYDVQQGEwJVSzEPMA0GA1UECBMGTG9uZG9uMQ8wDQYDVQQHEwZMb25kb24xDTAL
+BgNVBAoTBEZheWUxFTATBgNVBAMTDEphbWVzIENvZ2xhbjEgMB4GCSqGSIb3DQEJ
+ARYRamNvZ2xhbkBnbWFpbC5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB
+AMDjU5fAK7fvUCZIYHcGXDZD/m9bY+B/UcwGcowk0hMQGYNlLKrpiK7xXBmZpDb6
+r8n+7L/epBeSumbRIm4TDzeNHhuQGYLIeGQy7JNLoPBr6GxubjuJhKOOBnCqcupR
+CLGG7Zw5o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OsZyjbRI99pYkTdOpa5IPlIb3j3JbSfjAWHLxlRY
+0HLvN3Q1mE9kbB+uKH6syF/S7nALgsLgq7eHYvIaE/A=
+-----END RSA PRIVATE KEY-----

0 comments on commit 35e6d75

Please sign in to comment.
Something went wrong with that request. Please try again.