Created
April 24, 2015 22:06
-
-
Save reu/8b632b0fb22cf006a0f9 to your computer and use it in GitHub Desktop.
Node simple static file server.
This file contains hidden or 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 mime = require("mime-types"); | |
| var server = http.createServer(function(req, res) { | |
| var path = "." + req.url; | |
| fs.stat(path, function(error, stats) { | |
| if (error) { | |
| res.writeHead(404); | |
| res.end(); | |
| return | |
| } | |
| res.writeHead(200, { | |
| "Content-Type": mime.lookup(path), | |
| "Content-Length": stats.size, | |
| "Connection": "close" | |
| }); | |
| fs.createReadStream(path).pipe(res); | |
| }); | |
| }); | |
| server.listen(process.env.PORT || 5000); |
This file contains hidden or 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
| { | |
| "name": "node", | |
| "version": "1.0.0", | |
| "description": "Simple static file server", | |
| "main": "index.js", | |
| "scripts": { | |
| "start": "node index.js" | |
| }, | |
| "author": "Rodrigo Navarro <[email protected]>", | |
| "license": "MIT", | |
| "dependencies": { | |
| "mime-types": "^2.0.10" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Só faltou o charset na resposta =P