mirror of
https://github.com/azures04/crafatar.git
synced 2026-03-22 07:51:17 +01:00
Pipe static files, don't read to buffer
This commit is contained in:
parent
e26cff3718
commit
160629db6b
14
server.js
14
server.js
@ -20,18 +20,8 @@ function asset_request(req, res) {
|
|||||||
var filename = __dirname + "/public/" + req.url.path_list.join("/");
|
var filename = __dirname + "/public/" + req.url.path_list.join("/");
|
||||||
fs.exists(filename, function(exists) {
|
fs.exists(filename, function(exists) {
|
||||||
if (exists) {
|
if (exists) {
|
||||||
fs.readFile(filename, function(err, file_buffer) {
|
res.writeHead(200, { "Content-type" : mime.lookup(filename) });
|
||||||
if (err) {
|
fs.createReadStream(filename).pipe(res);
|
||||||
res.writeHead(500, {"Content-type" : "text/plain"});
|
|
||||||
res.end("Internal Server Error");
|
|
||||||
} else {
|
|
||||||
res.writeHead(200, {
|
|
||||||
"Content-type" : mime.lookup(filename),
|
|
||||||
"Content-Length": file_buffer.length
|
|
||||||
});
|
|
||||||
res.end(file_buffer);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
res.writeHead(404, {
|
res.writeHead(404, {
|
||||||
"Content-type" : "text/plain"
|
"Content-type" : "text/plain"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user