Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' of github.com:serby/versionator
  • Loading branch information
serby committed Feb 14, 2014
2 parents f465c53 + 416ae3e commit 38e65f7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/middleware/mapped.js
@@ -1,3 +1,5 @@
var url = require('url')

module.exports = function(mappedPaths) {

var reverseMap = Object.create(null)
Expand Down Expand Up @@ -45,8 +47,11 @@ module.exports = function(mappedPaths) {
return next()
}

req.url = reverseMap[req.url] || req.url
var parsedUrl = url.parse(req.url)
, origPath = reverseMap[parsedUrl.pathname]

if (origPath) req.url = origPath + parsedUrl.search
next()
}
}
}
}
13 changes: 12 additions & 1 deletion test/mapped-versionator.test.js
Expand Up @@ -126,6 +126,17 @@ describe('versionator', function() {
done()
})
})

it('req.url mapped url (with query string) is mapped correctly', function(done) {

var app = startServer({'/images/sprite.png': '/images/VERSIONHASH/sprite.png' }, 9901).app

request('http://localhost:9901/images/VERSIONHASH/sprite.png?key=val', function(error, response, data) {
data.should.eql('/images/sprite.png?key=val')
app.close()
done()
})
})

it('req.url mapped url is mapped correctly after hash change', function(done) {

Expand All @@ -144,4 +155,4 @@ describe('versionator', function() {

})

})
})

0 comments on commit 38e65f7

Please sign in to comment.