Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var urls = {}
- require( "http" ).createServer( function( req, res ) {
- var url = req.url, timeout
- if ( url == "/favicon.ico" ) return res.writeHead( 404 ), res.end()
- if ( url in urls ) return urls[ url ]( req, res )
- url = "/vapor.js?" + Math.floor( Math.random() * 0xcfd41b9100000 ).toString( 36 )
- urls[ url ] = function( req, response ) {
- // this is called if the user agent has javascript enabled
- clearTimeout( timeout )
- delete urls[ url ]
- res.end( "<script>document.body.innerHTML = 'rendered by js'</script></body></html>" )
- response.writeHead( 204, { "Content-Type": "text/javascript" } )
- response.end( "" ) // Copyright (c) 2010 Thomas Fuchs
- }
- timeout = setTimeout( function() {
- // this is called if the user agent does not have javascript enabled
- delete urls[ url ]
- res.end( "rendered by html</body></html>" )
- }, 1000 )
- res.writeHead( 200, { "Content-Type": "text/html" } )
- res.write( "<html><body><script src='" + url + "'></script>" )
- }).listen( 4011 )
Add Comment
Please, Sign In to add comment