Skip to content

Instantly share code, notes, and snippets.

@levity
Created September 13, 2011 20:25
Show Gist options
  • Save levity/1215050 to your computer and use it in GitHub Desktop.
Save levity/1215050 to your computer and use it in GitHub Desktop.
stub for ssl bookmarklet server
https = require 'https'
fs = require 'fs'
options = {
key: fs.readFileSync('privatekey.pem'),
cert: fs.readFileSync('certificate.pem')
}
host = 'levityisland.com'
server = https.createServer options, (req, res) ->
res.writeHead(200, {
'Content-Type': 'application/javascript',
'Access-Control-Allow-Origin': '*'
})
# in a real application of course you would only want this to be returned for one
# path, and have a handler for incoming data on another path.
res.end """
var jqs = document.createElement('script');
jqs.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
var afterLoad = setInterval(function() {
if (typeof(jQuery) == 'undefined') return;
clearInterval(afterLoad);
$.ajax({
url: 'https://#{host}/?arbitrary-data',
success: function() {
alert('data sent!');
},
dataType: 'text'
});
}, 100);
document.getElementsByTagName('head')[0].appendChild(jqs);
"""
console.log req.url
console.log "#{k}: #{v}" for k, v of req.headers
server.listen 443
# to generate cert files:
# 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
#
# for an explanation of 'Access-Control-Allow-Origin', see:
# http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment