|
1 | 1 | var parseRange = require("range-parser");
|
2 | 2 | var pathIsAbsolute = require("path-is-absolute");
|
3 | 3 | var MemoryFileSystem = require("memory-fs");
|
| 4 | +var HASH_REGEXP = /[0-9a-f]{10,}/; |
4 | 5 |
|
5 | 6 | module.exports = function Shared(context) {
|
6 | 7 | var share = {
|
@@ -49,6 +50,7 @@ module.exports = function Shared(context) {
|
49 | 50 | }
|
50 | 51 | },
|
51 | 52 | handleRangeHeaders: function handleRangeHeaders(content, req, res) {
|
| 53 | + //assumes express API. For other servers, need to add logic to access alternative header APIs |
52 | 54 | res.setHeader("Accept-Ranges", "bytes");
|
53 | 55 | if(req.headers.range) {
|
54 | 56 | var ranges = parseRange(content.length, req.headers.range);
|
@@ -165,6 +167,21 @@ module.exports = function Shared(context) {
|
165 | 167 | context.forceRebuild = true;
|
166 | 168 | }
|
167 | 169 | },
|
| 170 | + handleRequest: function(filename, processRequest, req) { |
| 171 | + // in lazy mode, rebuild on bundle request |
| 172 | + if(context.options.lazy && (!context.options.filename || context.options.filename.test(filename))) |
| 173 | + share.rebuild(); |
| 174 | + if(HASH_REGEXP.test(filename)) { |
| 175 | + try { |
| 176 | + if(context.fs.statSync(filename).isFile()) { |
| 177 | + processRequest(); |
| 178 | + return; |
| 179 | + } |
| 180 | + } catch(e) { |
| 181 | + } |
| 182 | + } |
| 183 | + share.ready(processRequest, req); |
| 184 | + }, |
168 | 185 | waitUntilValid: function(callback) {
|
169 | 186 | callback = callback || function() {};
|
170 | 187 | share.ready(callback, {});
|
|
0 commit comments