Skip to content
This repository was archived by the owner on Sep 13, 2018. It is now read-only.

Adding Support For Caching Headers (because 301 is forever) #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ In order to run the `redirect` application, you will need to modify the `config.
"redirects": {
"localhost": {
"host": "http://pksunkara.github.com",
"headers": {
"Cache-Control": "public,max-age=600"
},
"code": 302
},
"*": {
Expand Down
3 changes: 3 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"redirects": {
"localhost": {
"host": "http://pksunkara.github.com",
"headers": {
"Cache-Control": "public,max-age=600"
},
"code": 302
},
"*": {
Expand Down
7 changes: 7 additions & 0 deletions lib/redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ module.exports = function (redirects, port) {
res.statusCode = redirect.code || 302;
res.setHeader('Content-Type', 'text/plain');
res.setHeader('Location', newUrl);

if(redirect.headers) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (

for(var header in redirect.headers) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this the following:

Object.keys(redirect.headers).forEach(function (header) {

res.setHeader(header, redirect.headers[header]);
}
}

res.end('Redirecting to '+newUrl);
} else {
// there is no catch all, we will just show an error message
Expand Down