Skip to content

Instantly share code, notes, and snippets.

@apaleslimghost
Created March 18, 2013 10:33
Show Gist options
  • Save apaleslimghost/5186282 to your computer and use it in GitHub Desktop.
Save apaleslimghost/5186282 to your computer and use it in GitHub Desktop.
Simulate an import.io backend where the ES morelikethis 404s.
fs = require \fs
http = require \http
global.options = JSON.parse fs.read-file-sync "importio-webui/options.json" \utf8
console.log options
http.create-server (req,res)->
if req.url == /_mlt$/
res.write-head 404 "Not Found"
# lol jetty 404
res.end """
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 404 Not Found</title>
</head>
<body>
<h2>HTTP ERROR: 404</h2>
<p>Problem accessing #{req.url}. Reason:
<pre> Not Found</pre></p>
<hr /><i><small>Powered by Jetty://</small></i>
</body>
</html>
"""
else
opts = {
...options.remote.api
req.method
path: req.url
req.headers
}
req.pipe http.request opts, (response)->
res.write-head response.status-code, response.headers
response.pipe res
.listen 8001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment