Skip to content

Instantly share code, notes, and snippets.

@IvanLysenko
Last active December 20, 2015 19:49
Show Gist options
  • Save IvanLysenko/6185676 to your computer and use it in GitHub Desktop.
Save IvanLysenko/6185676 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head></head>
<body>
<p><a href='/testtext.txt' >Save as to download document</a></p>
<p><a href='/logo.png'>test image hosted</a></p>
</body>
</html>
var http = require('http')
var fs = require('fs')
var ecstatic = require('ecstatic')(__dirname + '/files')
var onRequest = function(request, response){
fs.readFile('./HostPage.htm', function(err, data){
if(err){
response.writeHeader(404, {'Content-Type': 'text/html'})
response.end('404')
return
}
response.writeHeader(200, {'Content-Type': 'text/html'})
response.write(data)
response.end()
})
}
http.createServer(onRequest).listen(8080)
here is an example file for hosting
@mikolalysenko
Copy link

The problem is that you are writing the same file out for each request. A better way do this would be:

var onRequest = function(request, response) { ecstatic(request, response) }

You need to call ecstatic to actually use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment