Skip to content

Commit

Permalink
add a map for redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
zeke committed Feb 6, 2015
1 parent 9845b8f commit ead7f48
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ can be overridden by using a numerical `order` frontmatter property. It is
not necessary to order all pages in a section: Any pages in a section that
don't have an `order` property will be relegated to the end of that section.

## Redirects

If you rename or remove a file, add it to [lib/redirects.js](lib/redirects.js) too keep
things from breaking.

## Development

Download node at [nodejs.org](http://nodejs.org) and install it, if you haven't already.
Expand Down
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var isNumber = require("lodash").isNumber
var sortBy = require("lodash").sortBy
var any = require("lodash").any
var suggest = require(__dirname + "/lib/suggestions")
var redirects = require(__dirname + "/lib/redirects")

// Load section and page data
var content = require(path.resolve(__dirname, "content.json"))
Expand Down Expand Up @@ -81,6 +82,11 @@ app.get("/all", function(req, res) {
})

app.get("/*", function(req, res) {

if (req.path in redirects) {
return res.redirect(301, redirects[req.path])
}

var page = find(content.pages, function(page) {
return page.href === req.path
})
Expand Down
3 changes: 3 additions & 0 deletions lib/redirects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
"/enterprise/whitelist": "/enterprise/mirroring",
}
10 changes: 10 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,13 @@ describe('GET /cli/nonexistent', function() {
})
})
})

describe('redirects', function() {

it('301s whitelist to mirroring', function(done) {
supertest(app)
.get('/enterprise/whitelist')
.expect('Location', /\/enterprise\/mirroring/)
.expect(301, done)
})
})

0 comments on commit ead7f48

Please sign in to comment.