Last active
December 20, 2015 19:49
-
-
Save IvanLysenko/6185676 to your computer and use it in GitHub Desktop.
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
<!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> | |
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
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) | |
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
here is an example file for hosting |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem is that you are writing the same file out for each request. A better way do this would be:
You need to call ecstatic to actually use it.