Skip to content

Commit

Permalink
fix request root dir without pathname
Browse files Browse the repository at this point in the history
  • Loading branch information
Secbone committed Aug 22, 2016
1 parent 5e07e75 commit 0881885
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function serve(path, root) {
req_path_array = req_path_array.slice(1);
}

return send(ctx, req_path_array.join("/"), {root: root}).then(() => {
return send(ctx, req_path_array.join("/") || "/", {root: root}).then(() => {
return next();
});
}
Expand Down
14 changes: 14 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ describe("Koa-static2", () => {
it("should work when serve the root path", done => {
const app = new Koa();
app.use(serve("/", __dirname));
app.use(function(ctx, next) {
if(ctx.path == "/"){
ctx.body = "ok";
}
});

request(app.listen())
.get("/")
.expect(200, "ok", done)
});

it("should work when serve the root path and get correct content", done => {
const app = new Koa();
app.use(serve("/", __dirname));

request(app.listen())
.get("/some.txt")
Expand Down

0 comments on commit 0881885

Please sign in to comment.