Created
June 12, 2014 01:43
-
-
Save hems/3b7c3ec4c01cb3006bd9 to your computer and use it in GitHub Desktop.
remixing a website using node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# - 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