Skip to content

Commit

Permalink
preventing the serving of source files
Browse files Browse the repository at this point in the history
  • Loading branch information
sintaxi committed Oct 10, 2013
1 parent 7a5b0e0 commit bdfdabc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ exports.server = function(dirPath, options, callback){
middleware.regProjectFinder(dirPath),
middleware.setup,
middleware.underscore,
middleware.mwl,
middleware.static,
middleware.poly,
middleware.process,
Expand All @@ -48,6 +49,7 @@ exports.multihost = function(dirPath, options, callback){
middleware.hostProjectFinder(dirPath),
middleware.setup,
middleware.underscore,
middleware.mwl,
middleware.static,
middleware.poly,
middleware.process,
Expand Down
16 changes: 16 additions & 0 deletions lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,22 @@ exports.underscore = function(req, rsp, next){
}
}

/**
* Modern Web Language
*
* Returns 404 if file is a precompiled
*
*/
exports.mwl = function(req, rsp, next){
var ext = path.extname(req.url).replace(/^\./, '')

if(polymer.helpers.processors["html"].indexOf(ext) !== -1 || polymer.helpers.processors["css"].indexOf(ext) !== -1 || polymer.helpers.processors["js"].indexOf(ext) !== -1){
notFound(req, rsp, next)
}else{
next()
}
}

/**
* Static
*
Expand Down
30 changes: 15 additions & 15 deletions test/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,55 +119,55 @@ describe("headers", function(){

// direct

it("should be correct with a valid Jade file", function(done){
it("should be correct when Jade file requested", function(done){
superagent.agent().get("http://localhost:" + port + "/valid-jade.jade").end(function(err, rsp){
rsp.should.have.status(200)
rsp.should.have.status(404)
rsp.headers.should.have.property("content-type", "text/html; charset=UTF-8")
rsp.headers.should.have.property("content-length")
done()
})
})

it("should be correct with a valid EJS file", function(done){
it("should be correct when EJS file requested", function(done){
superagent.agent().get("http://localhost:" + port + "/valid-ejs.ejs").end(function(err, rsp){
rsp.should.have.status(200)
rsp.should.have.status(404)
rsp.headers.should.have.property("content-type", "text/html; charset=UTF-8")
rsp.headers.should.have.property("content-length")
done()
})
})

it("should be correct with a valid Markdown file", function(done){
it("should be correct when Markdown file requested", function(done){
superagent.agent().get("http://localhost:" + port + "/valid-markdown.md").end(function(err, rsp){
rsp.should.have.status(200)
rsp.should.have.status(404)
rsp.headers.should.have.property("content-type", "text/html; charset=UTF-8")
rsp.headers.should.have.property("content-length")
done()
})
})

it("should be correct with a valid CoffeeScript file", function(done){
it("should be correct when CoffeeScript file requested", function(done){
superagent.agent().get("http://localhost:" + port + "/valid-coffee.coffee").end(function(err, rsp){
rsp.should.have.status(200)
rsp.headers.should.have.property("content-type", "application/javascript")
rsp.should.have.status(404)
rsp.headers.should.have.property("content-type", "text/html; charset=UTF-8")
rsp.headers.should.have.property("content-length")
done()
})
})

it("should be correct with a valid LESS file", function(done){
it("should be correct when LESS file requested", function(done){
superagent.agent().get("http://localhost:" + port + "/valid-less.less").end(function(err, rsp){
rsp.should.have.status(200)
rsp.headers.should.have.property("content-type", "text/css; charset=UTF-8")
rsp.should.have.status(404)
rsp.headers.should.have.property("content-type", "text/html; charset=UTF-8")
rsp.headers.should.have.property("content-length")
done()
})
})

it("should be correct with a valid Stylus file", function(done){
it("should be correct when Stylus file requested", function(done){
superagent.agent().get("http://localhost:" + port + "/valid-styl.styl").end(function(err, rsp){
rsp.should.have.status(200)
rsp.headers.should.have.property("content-type", "text/css; charset=UTF-8")
rsp.should.have.status(404)
rsp.headers.should.have.property("content-type", "text/html; charset=UTF-8")
rsp.headers.should.have.property("content-length")
done()
})
Expand Down

0 comments on commit bdfdabc

Please sign in to comment.