Skip to content

Commit

Permalink
support content and public dirs in http (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
s3ththompson authored Apr 8, 2018
1 parent 0f7ce4c commit ce74f75
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions http.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ function start (entry, opts) {
})
})

router.route(/^\/assets\/([^?]*)(\?.*)?$/, function (req, res, params) {
var prefix = 'assets' // TODO: also accept 'content'
var name = prefix + '/' + params[1]
router.route(/^\/(assets|content|public)\/([^?]*)(\?.*)?$/, function (req, res, params) {
var prefix = params[1] // asset dir
var name = prefix + '/' + params[2]
compiler.assets(name, function (err, filename) {
if (err) {
res.statusCode = 404
Expand Down
8 changes: 5 additions & 3 deletions test/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,20 @@ function setup () {

var dirname = 'manifest-pipeline-' + (Math.random() * 1e4).toFixed()
tmpDirname = path.join(os.tmpdir(), dirname)
var contentDirname = path.join(tmpDirname, 'content')
var assetDirname = path.join(tmpDirname, 'assets')
var assetSubdirname = path.join(assetDirname, 'images')

tmpScriptname = path.join(tmpDirname, 'index.js')
var tmpFilename = path.join(assetDirname, 'file.txt')
var tmpFilename = path.join(contentDirname, 'file.txt')
var tmpAssetJsFilename = path.join(assetDirname, 'file.js')
var tmpAssetCssFilename = path.join(assetDirname, 'file.css')
var tmpJsonFilename = path.join(assetDirname, 'file.json')
var tmpJpgFilename = path.join(assetDirname, 'file.jpg')
var tmpJpgSubFilename = path.join(assetSubdirname, 'file.jpg')

fs.mkdirSync(tmpDirname)
fs.mkdirSync(contentDirname)
fs.mkdirSync(assetDirname)
fs.mkdirSync(assetSubdirname)
fs.writeFileSync(tmpScriptname, script)
Expand Down Expand Up @@ -74,8 +76,8 @@ tape('should route urls appropriately', function (assert) {
'/bundle.js?cache=busted',
'/bundle.css',
'/bundle.css?cache=busted',
'/assets/file.txt',
'/assets/file.txt?cache=busted',
'/content/file.txt',
'/content/file.txt?cache=busted',
'/assets/file.json',
'/assets/file.css',
'/assets/file.css?cache=busted',
Expand Down

0 comments on commit ce74f75

Please sign in to comment.