UNPKG

instant

Version:

drop-in replacement for connect.static with live-reload support

20 lines (17 loc) 543 B
var tamper = require('tamper') /** * Returns a middleware that injects a script tag with the given URL before * the closing body tag of text/html responses. */ module.exports = function(script) { return tamper(function(req, res) { var url = req.realUrl || req.url , mime = res.getHeader('Content-Type') if (/text\/html/.test(mime) && !/instant\/events/.test(url)) { return function(body) { return body.replace(/<\/body>/i, ' <script src="' + script + '"></script>\n</body>') } } }) }