Personal blog written from scratch using Node.js, Bootstrap, and MySQL. https://jrtechs.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

35 lines
1.3 KiB

const utils = require('../utils/utils.js');
const crypto = require('crypto');
module.exports=
{
/**Sends the user an image from the specified fileName.
*
* @param result
* @param fileName
*/
main: function(result, fileName, cache)
{
//result.contentType = 'image/png';
var js = cache.get(fileName);
if(js == null)
{
utils.include("." + fileName).then(function(content)
{
var eTag = crypto.createHash('md5').update(content).digest('hex');
result.writeHead(200, {'Content-Type': 'application/javascript', 'Cache-Control': 'public, max-age=2678400', 'ETag': '"' + eTag + '"', 'Vary': 'Accept-Encoding'});
result.write(content);
result.end();
cache.put(content);
});
}
else
{
var eTag = crypto.createHash('md5').update(js).digest('hex');
result.writeHead(200, {'Content-Type': 'application/javascript', 'Cache-Control': 'public, max-age=2678400', 'ETag': '"' + eTag + '"', 'Vary': 'Accept-Encoding'});
result.write(js);
result.end();
}
}
};