solidusjs / solidus

A simple server that generates pages from JSON and Templates
MIT License
28 stars 7 forks source link

Redirects should 'default' to temporary #62

Closed Fauntleroy closed 10 years ago

Fauntleroy commented 11 years ago

Right now if you just put in to and from your redirect will be permanent, and this can cause problems. Ideally unspecified redirects would be temporary, and permanent redirects would require something explicit. Here's my proposal:

// explicitly permanent
[{
    "from": "/",
    "to": "http://www.google.com",
    "permanent": true
},
// implicitly temporary. Will be active indefinitely but always use 302
{
    "from": "/tandem",
    "to": "http://www.tandem.io"
},
// explicitly temporary. Will be active between start and end datetimes
{
    "from": "/sync",
    "to": "http://www.tksync.com",
    "start": "2000-1-1 00:00:00",
    "end": "2020-1-1 00:00:00"
}]
Fauntleroy commented 11 years ago

@pushred does that look good to you?

pushred commented 11 years ago

Nice & explicit.

Fauntleroy commented 11 years ago

Having trouble figuring out how exactly to make start and end actually work for redirects, so I'm going to comment out loud here. In order to have these redirects work properly, we need to check the redirect's date every time a request is made to the from route. This is simple enough until I think about this case: Someone has a page at /cats, but they have a temporary redirect "from": "/cats", "to": "https://www.google.com/search?q=cats" as well. In this case the ideal behavior would be to follow the redirect while it's valid, and to go to the page when it is not. However, I'm not seeing a clear path for doing this in Express, as the redirect method is used inside of route verbs, and I don't know if there's a fallback method to go from one route handler to another one.

Fauntleroy commented 11 years ago

One idea is to merge the creation of routes between views and redirects. When a view registers its route with Express, I could check to see if any redirects exist for that route, then put a redirect middleware function in front of the view's callback.

Fauntleroy commented 10 years ago

https://github.com/SparkartGroupInc/solidus/pull/67