Skip to content

Instantly share code, notes, and snippets.

@hems
Created June 12, 2014 01:43
Show Gist options
  • Save hems/3b7c3ec4c01cb3006bd9 to your computer and use it in GitHub Desktop.
Save hems/3b7c3ec4c01cb3006bd9 to your computer and use it in GitHub Desktop.
remixing a website using node.js
#
# - save this file as server.coffee
# - create a remix.js file with the js you want to remix
# - do your magic
#
express = require 'express'
app = express()
request = require 'request'
hyperstream = require('hyperstream')
fs = require 'fs'
app.get '/remix.js', (req,res) ->
file = fs.createReadStream( __dirname + '/remix.js' )
file.pipe( res )
app.get '*', (req, res) ->
url = 'http://www.google.com/' + req.url
if req.url == '/'
proxy = request( url )
hs = hyperstream 'head': "<script src='/remix.js'></script>"
proxy.pipe( hs ).pipe( res );
else
proxy = request( url )
req.pipe( proxy ).pipe( res )
app.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment