Guest User

Untitled

a guest
Jun 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. var urls = {}
  2.  
  3. require( "http" ).createServer( function( req, res ) {
  4. var url = req.url, timeout
  5.  
  6. if ( url == "/favicon.ico" ) return res.writeHead( 404 ), res.end()
  7.  
  8. if ( url in urls ) return urls[ url ]( req, res )
  9.  
  10. url = "/vapor.js?" + Math.floor( Math.random() * 0xcfd41b9100000 ).toString( 36 )
  11.  
  12. urls[ url ] = function( req, response ) {
  13. // this is called if the user agent has javascript enabled
  14.  
  15. clearTimeout( timeout )
  16. delete urls[ url ]
  17.  
  18. res.end( "<script>document.body.innerHTML = 'rendered by js'</script></body></html>" )
  19.  
  20. response.writeHead( 204, { "Content-Type": "text/javascript" } )
  21. response.end( "" ) // Copyright (c) 2010 Thomas Fuchs
  22. }
  23.  
  24. timeout = setTimeout( function() {
  25. // this is called if the user agent does not have javascript enabled
  26.  
  27. delete urls[ url ]
  28. res.end( "rendered by html</body></html>" )
  29. }, 1000 )
  30.  
  31. res.writeHead( 200, { "Content-Type": "text/html" } )
  32. res.write( "<html><body><script src='" + url + "'></script>" )
  33. }).listen( 4011 )
Add Comment
Please, Sign In to add comment