lib/client/serve/utils.js
'use strict';
// Client Asset Serving Shared Utils
exports.serve = {
js: function (body, response) {
return serve(body, 'text/javascript; charset=utf-8', response);
},
css: function (body, response) {
return serve(body, 'text/css', response);
}
};
// TODO - consider replacing with Node public API - PJENSEN
//
exports.parseUrl = function (url) {
var cleanUrl;
cleanUrl = url.split('&')[0];
return cleanUrl.split('?')[1];
};
// Private
function serve(body, type, response) {
response.writeHead(200, {
'Content-type': type,
'Content-Length': (typeof body === 'string')? Buffer.byteLength(body) : body.length
});
return response.end(body);
}