From a6fca003ac8bee149b4223964df4dc9d972b656b Mon Sep 17 00:00:00 2001 From: Brock Whitten Date: Sat, 28 Feb 2015 01:20:40 -0800 Subject: [PATCH 01/10] verison bump v0.16.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2b906592..b05d28bf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "harp", - "version": "0.15.2", + "version": "0.16.0", "description": "Static web server with built in preprocessing", "author": "Brock Whitten ", "contributors": From c880d870e34879628ea4723fb3b5df1a2588c439 Mon Sep 17 00:00:00 2001 From: Brock Whitten Date: Sat, 28 Feb 2015 02:26:17 -0800 Subject: [PATCH 02/10] update tests for slash indifference --- lib/middleware.js | 3 +- .../slash-indifference/directory/index.html | 1 + test/apps/slash-indifference/file.html | 1 + test/slash-indifference.js | 51 +++++++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 test/apps/slash-indifference/directory/index.html create mode 100644 test/apps/slash-indifference/file.html create mode 100644 test/slash-indifference.js diff --git a/lib/middleware.js b/lib/middleware.js index 385dd13b..2d5c4388 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -74,7 +74,7 @@ exports.index = function(dirPath){ }); } }); - + poly.render("index.jade", { pkg: pkg, projects: projects, layout: "_layout.jade" }, function(error, body){ rsp.end(body) }); @@ -343,6 +343,7 @@ exports.static = function(req, res, next) { } function directory() { + if (!redirect) return resume(); var pathname = url.parse(req.originalUrl).pathname; res.statusCode = 301; diff --git a/test/apps/slash-indifference/directory/index.html b/test/apps/slash-indifference/directory/index.html new file mode 100644 index 00000000..c49147e2 --- /dev/null +++ b/test/apps/slash-indifference/directory/index.html @@ -0,0 +1 @@ +

file in directory contents

\ No newline at end of file diff --git a/test/apps/slash-indifference/file.html b/test/apps/slash-indifference/file.html new file mode 100644 index 00000000..0517c91a --- /dev/null +++ b/test/apps/slash-indifference/file.html @@ -0,0 +1 @@ +

file contents

\ No newline at end of file diff --git a/test/slash-indifference.js b/test/slash-indifference.js new file mode 100644 index 00000000..6758d844 --- /dev/null +++ b/test/slash-indifference.js @@ -0,0 +1,51 @@ +var should = require("should") +var request = require('request') +var path = require("path") +var fs = require("fs") +var exec = require("child_process").exec +var harp = require("../") + +describe("slash-indifference", function(){ + var projectPath = path.join(__dirname, "apps/slash-indifference") + + before(function(done){ + harp.server(projectPath, { port: 8119 }, done) + }) + + describe("file", function(){ + it("should get 200 without slash", function(done){ + request('http://localhost:8119/file', { followRedirect: false }, function(e, r, b){ + r.statusCode.should.eql(200) + b.should.eql("

file contents

") + done() + }) + }) + + it("should get redirected when slash present", function(done){ + request('http://localhost:8119/file/', { followRedirect: false }, function(e, r, b){ + r.statusCode.should.eql(301) + r.headers["location"].should.eql("/file") + done() + }) + }) + }) + + describe("directory", function(){ + it("should get 200 with slash", function(done){ + request('http://localhost:8119/directory/', { followRedirect: false }, function(e, r, b){ + r.statusCode.should.eql(200) + b.should.eql("

file in directory contents

") + done() + }) + }) + + it("should get redirected when slash absent", function(done){ + request('http://localhost:8119/directory', { followRedirect: false }, function(e, r, b){ + r.statusCode.should.eql(301) + r.headers["location"].should.eql("/directory/") + done() + }) + }) + }) + +}) From ebb656f25ded12b54e95b608aebd0bb1a7799d33 Mon Sep 17 00:00:00 2001 From: Brock Whitten Date: Sat, 28 Feb 2015 11:48:18 -0800 Subject: [PATCH 03/10] tests passing for intelegent indifference on trailing slashes --- lib/middleware.js | 120 +++++++++++++++++++++++++++++----------------- 1 file changed, 76 insertions(+), 44 deletions(-) diff --git a/lib/middleware.js b/lib/middleware.js index 2d5c4388..f9ca84a9 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -464,65 +464,97 @@ exports.process = function(req, rsp, next){ var priorityList = terraform.helpers.buildPriorityList(normalizedPath) var sourceFile = terraform.helpers.findFirstFile(req.setup.publicPath, priorityList) + /** * We GTFO if we don't have a source file. */ - if(!sourceFile) return next() + if(!sourceFile){ + if (path.basename(normalizedPath) === "index.html") { + var pathAr = normalizedPath.split("/"); pathAr.pop() // Pop index.html off the list + var prospectCleanPath = pathAr.join("/") + var prospectNormalizedPath = helpers.normalizeUrl(prospectCleanPath) + var prospectPriorityList = terraform.helpers.buildPriorityList(prospectNormalizedPath) + prospectPriorityList.push(path.basename(prospectNormalizedPath + ".html")) + sourceFile = terraform.helpers.findFirstFile(req.setup.publicPath, prospectPriorityList) - /** - * Now we let terraform handle the asset pipeline. - */ + if (!sourceFile) { + return next() + } else { + // 301 redirect + rsp.statusCode = 301 + rsp.setHeader('Location', prospectCleanPath) + rsp.end('Redirecting to ' + utils.escape(prospectCleanPath)) + } - req.poly.render(sourceFile, function(error, body){ - if(error){ - error.stack = helpers.stacktrace(error.stack, { lineno: error.lineno }) + } else { + return next() + } + } else { - var locals = { - project: req.headers.host, - error: error, - pkg: pkg - } - if(terraform.helpers.outputType(sourceFile) == 'css'){ - var outputType = terraform.helpers.outputType(sourceFile) - var mimeType = helpers.mimeType(outputType) - var charset = mime.charsets.lookup(mimeType) - var body = helpers.cssError(locals) - rsp.statusCode = 200 - rsp.setHeader('Content-Type', mimeType + (charset ? '; charset=' + charset : '')) - rsp.setHeader('Content-Length', Buffer.byteLength(body, charset)) - rsp.end(body) - }else{ + /** + * Now we let terraform handle the asset pipeline. + */ - // Make the paths relative but keep the root dir. - // TODO: move to helper. - // - // var loc = req.projectPath.split(path.sep); loc.pop() - // var loc = loc.join(path.sep) + path.sep - // if(error.filename) error.filename = error.filename.replace(loc, "") + req.poly.render(sourceFile, function(error, body){ + if(error){ + error.stack = helpers.stacktrace(error.stack, { lineno: error.lineno }) - terraform.root(__dirname + "/templates").render("error.jade", locals, function(err, body){ - var mimeType = helpers.mimeType('html') + var locals = { + project: req.headers.host, + error: error, + pkg: pkg + } + if(terraform.helpers.outputType(sourceFile) == 'css'){ + var outputType = terraform.helpers.outputType(sourceFile) + var mimeType = helpers.mimeType(outputType) var charset = mime.charsets.lookup(mimeType) - rsp.statusCode = 500 + var body = helpers.cssError(locals) + rsp.statusCode = 200 rsp.setHeader('Content-Type', mimeType + (charset ? '; charset=' + charset : '')) rsp.setHeader('Content-Length', Buffer.byteLength(body, charset)) rsp.end(body) - }) + }else{ + + // Make the paths relative but keep the root dir. + // TODO: move to helper. + // + // var loc = req.projectPath.split(path.sep); loc.pop() + // var loc = loc.join(path.sep) + path.sep + // if(error.filename) error.filename = error.filename.replace(loc, "") + + terraform.root(__dirname + "/templates").render("error.jade", locals, function(err, body){ + var mimeType = helpers.mimeType('html') + var charset = mime.charsets.lookup(mimeType) + rsp.statusCode = 500 + rsp.setHeader('Content-Type', mimeType + (charset ? '; charset=' + charset : '')) + rsp.setHeader('Content-Length', Buffer.byteLength(body, charset)) + rsp.end(body) + }) + } + }else{ + // 404 + if(!body) return next() + + var outputType = terraform.helpers.outputType(sourceFile) + var mimeType = helpers.mimeType(outputType) + var charset = mime.charsets.lookup(mimeType) + rsp.statusCode = 200 + rsp.setHeader('Content-Type', mimeType + (charset ? '; charset=' + charset : '')) + rsp.setHeader('Content-Length', Buffer.byteLength(body, charset)); + rsp.end(body); } - }else{ - // 404 - if(!body) return next() + }) + } + + + + + + + + - var outputType = terraform.helpers.outputType(sourceFile) - var mimeType = helpers.mimeType(outputType) - var charset = mime.charsets.lookup(mimeType) - rsp.statusCode = 200 - rsp.setHeader('Content-Type', mimeType + (charset ? '; charset=' + charset : '')) - rsp.setHeader('Content-Length', Buffer.byteLength(body, charset)); - rsp.end(body); - } - }) } From 948cab0bd68aac240089c94b2a5c6b4af508d76c Mon Sep 17 00:00:00 2001 From: Eric Drechsel Date: Tue, 17 Mar 2015 11:27:07 -0700 Subject: [PATCH 04/10] Add failing test for skipping .git dir in root style apps --- test/apps/compile/root/_harp.json | 1 + test/compile.js | 39 ++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 test/apps/compile/root/_harp.json diff --git a/test/apps/compile/root/_harp.json b/test/apps/compile/root/_harp.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/test/apps/compile/root/_harp.json @@ -0,0 +1 @@ +{} diff --git a/test/compile.js b/test/compile.js index c566ca37..9dce3b20 100644 --- a/test/compile.js +++ b/test/compile.js @@ -48,10 +48,47 @@ describe("compile", function(){ }) + describe("root app", function(){ + var projectPath = path.join(__dirname, "apps/compile/root") + var outputPath = path.join(__dirname, "out/compile-root") + + // Making this at runtime since git refuses to store .git dirs + fs.mkdirSync(path.join(projectPath, ".git")); + fs.openSync(path.join(projectPath, "/.git/foo"), 'a') + + it("should compile", function(done){ + harp.compile(projectPath, outputPath, function(error){ + should.not.exist(error) + done() + }) + }) + + it("should not include .git", function(done) { + var rsp = fs.existsSync(path.join(projectPath, ".git/foo")) + rsp.should.be.true + + var rsp = fs.existsSync(path.join(outputPath, ".git/foo")) + rsp.should.be.false + + var rsp = fs.existsSync(path.join(outputPath, "git")) + rsp.should.be.false + + done() + }) + + after(function(done){ + exec("rm -rf " + path.join(projectPath, ".git"), function(){ + done() + }) + }) + + }) + + after(function(done){ exec("rm -rf " + path.join(__dirname, "out"), function(){ done() }) }) -}) \ No newline at end of file +}) From 62dbba5963a1bc2e5741f8c48dd6562f30e8c658 Mon Sep 17 00:00:00 2001 From: Eric Drechsel Date: Tue, 17 Mar 2015 11:27:34 -0700 Subject: [PATCH 05/10] Add failing test for skipping www/ in root style apps --- test/apps/compile/root/www/foo | 0 test/compile.js | 10 ++++++++++ 2 files changed, 10 insertions(+) create mode 100644 test/apps/compile/root/www/foo diff --git a/test/apps/compile/root/www/foo b/test/apps/compile/root/www/foo new file mode 100644 index 00000000..e69de29b diff --git a/test/compile.js b/test/compile.js index 9dce3b20..b6e54602 100644 --- a/test/compile.js +++ b/test/compile.js @@ -76,6 +76,16 @@ describe("compile", function(){ done() }) + it("should not include www", function(done) { + var rsp = fs.existsSync(path.join(outputPath, "www/foo")) + rsp.should.be.false + + var rsp = fs.existsSync(path.join(outputPath, "www")) + rsp.should.be.false + + done() + }) + after(function(done){ exec("rm -rf " + path.join(projectPath, ".git"), function(){ done() From bcbdcbb87a7f3b372c95b2b5a9bfb5ed590a9378 Mon Sep 17 00:00:00 2001 From: Eric Drechsel Date: Wed, 18 Mar 2015 13:17:27 -0700 Subject: [PATCH 06/10] minimal test cases for project path containing output path #307 --- test/compile.js | 74 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 25 deletions(-) diff --git a/test/compile.js b/test/compile.js index b6e54602..3a02ad40 100644 --- a/test/compile.js +++ b/test/compile.js @@ -46,15 +46,25 @@ describe("compile", function(){ done() }) + after(function(done){ + exec("rm -rf " + outputPath, function() { + done(); + }) + }) + }) - describe("root app", function(){ - var projectPath = path.join(__dirname, "apps/compile/root") - var outputPath = path.join(__dirname, "out/compile-root") + describe("root app with .git dir", function(){ + var projectPath = path.join(__dirname, "apps","compile","root") + var outputPath = path.join(__dirname, "out","compile-root") + var gitPath = path.join(projectPath, ".git") + + // Make at runtime since git refuses to store .git dirs + if (!fs.existsSync(gitPath)) { + fs.mkdirSync(gitPath); + fs.openSync(path.join(gitPath, "foo"), 'a') + } - // Making this at runtime since git refuses to store .git dirs - fs.mkdirSync(path.join(projectPath, ".git")); - fs.openSync(path.join(projectPath, "/.git/foo"), 'a') it("should compile", function(done){ harp.compile(projectPath, outputPath, function(error){ @@ -63,41 +73,55 @@ describe("compile", function(){ }) }) - it("should not include .git", function(done) { - var rsp = fs.existsSync(path.join(projectPath, ".git/foo")) + it("should not include .git in output", function(done) { + var rsp = fs.existsSync(path.join(projectPath, ".git", "foo")) rsp.should.be.true - var rsp = fs.existsSync(path.join(outputPath, ".git/foo")) - rsp.should.be.false - - var rsp = fs.existsSync(path.join(outputPath, "git")) + var rsp = fs.existsSync(path.join(outputPath, ".git")) rsp.should.be.false done() }) - it("should not include www", function(done) { - var rsp = fs.existsSync(path.join(outputPath, "www/foo")) - rsp.should.be.false + after(function(done){ + exec("rm -rf " + outputPath + " " + gitPath, function() { + done(); + }) + }) - var rsp = fs.existsSync(path.join(outputPath, "www")) - rsp.should.be.false + }) - done() - }) + describe("root app with output dir containing .git in project dir", function(){ + var projectPath = path.join(__dirname, "apps","compile","root") + var outputPath = path.join(projectPath, "out") + var gitPath = path.join(outputPath, ".git") - after(function(done){ - exec("rm -rf " + path.join(projectPath, ".git"), function(){ + // Making this at runtime since git refuses to store .git dirs + if (!fs.existsSync(gitPath)) { + fs.mkdirSync(outputPath); + fs.mkdirSync(gitPath); + fs.openSync(path.join(gitPath, "foo"), 'a') + } + + + it("should compile", function(done){ + harp.compile(projectPath, outputPath, function(error){ + should.not.exist(error) done() }) }) - }) + it("should not include a copy of the output subpath in output", function(done) { + var rsp = fs.existsSync(path.join(outputPath, "out")) + rsp.should.be.false + done(); + }) - after(function(done){ - exec("rm -rf " + path.join(__dirname, "out"), function(){ - done() + after(function(done){ + exec("rm -rf " + outputPath, function() { + done(); + }) }) }) From ec0ca2fff95d4d64539538d3d1d436ec1d0d0cc2 Mon Sep 17 00:00:00 2001 From: Kenneth Ormandy Date: Sat, 18 Apr 2015 12:08:35 -0700 Subject: [PATCH 07/10] Version bump v0.17.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b05d28bf..e526880e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "harp", - "version": "0.16.0", + "version": "0.17.0", "description": "Static web server with built in preprocessing", "author": "Brock Whitten ", "contributors": From d6581c44ee5fdcbfdff75068d27b02f6643933b5 Mon Sep 17 00:00:00 2001 From: Kenneth Ormandy Date: Sat, 18 Apr 2015 12:08:46 -0700 Subject: [PATCH 08/10] Updates Terraform to v0.11.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e526880e..513e5946 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "url": "https://github.com/sintaxi/harp.git" }, "dependencies": { - "terraform": "0.10.3", + "terraform": "0.11.0", "commander": "2.0.0", "connect": "2.9.0", "fs-extra": "0.6.4", From 22f03abf148d61361df7e8733a198c252b010ea1 Mon Sep 17 00:00:00 2001 From: Kenneth Ormandy Date: Sat, 18 Apr 2015 15:52:37 -0700 Subject: [PATCH 09/10] Updates fs-extra --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 513e5946..4e825eab 100644 --- a/package.json +++ b/package.json @@ -36,8 +36,8 @@ "terraform": "0.11.0", "commander": "2.0.0", "connect": "2.9.0", - "fs-extra": "0.6.4", "async": "0.2.9", + "fs-extra": "0.18.2", "mime": "1.2.11", "download-github-repo": "0.1.3", "envy-json": "0.2.0" From 0b08f1ba16f32f057014e07b8d467d28a0593971 Mon Sep 17 00:00:00 2001 From: Kenneth Ormandy Date: Sat, 18 Apr 2015 15:52:48 -0700 Subject: [PATCH 10/10] Updates envy-json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4e825eab..2e51cf24 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "fs-extra": "0.18.2", "mime": "1.2.11", "download-github-repo": "0.1.3", - "envy-json": "0.2.0" + "envy-json": "0.2.1" }, "devDependencies": { "mocha": "1.8.1",