Skip to content

Commit

Permalink
hotfix: add no-cache Cache-Control to man.dvc.org redirects
Browse files Browse the repository at this point in the history
for #768
  • Loading branch information
jorgeorpinel committed Nov 4, 2019
1 parent c5fd89b commit e0c2de3
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ app.prepare().then(() => {
(req.headers['x-forwarded-proto'] !== 'https' && !dev) ||
req.headers.host.match(/^www/) !== null
) {
// Enforce https protocol and remove www from host/
// Enforce https protocol and remove www from host.
res.writeHead(301, {
Location: 'https://' + req.headers.host.replace(/^www\./, '') + req.url
})
Expand All @@ -34,6 +34,7 @@ app.prepare().then(() => {
// man.dvc.org/{cmd} -> dvc.org/doc/command-reference/{cmd},
// replace - for / in {cmd} except for /get-url, /import-url
res.writeHead(301, {
'Cache-Control': 'no-cache',
Location:
'https://dvc.org/doc/command-reference' +
(['/get-url', '/import-url'].indexOf(pathname) < 0
Expand All @@ -50,12 +51,30 @@ app.prepare().then(() => {
pathname
})
res.end()
} else if (/^\/(deb|rpm)\/.*/i.test(pathname)) {
// path /(deb|rpm) -> corresponding S3 bucket
res.writeHead(301, {
Location:
'https://s3-us-east-2.amazonaws.com/dvc-s3-repo/' +
pathname.substring(1)
})
res.end()
} else if (/^\/(help|chat)\/?$/i.test(pathname)) {
// path /(help|chat) -> Discord chat invite
res.writeHead(301, { Location: 'https://discordapp.com/invite/dvwXA2N' })
res.end()
} else if (/^\/doc\/commands-reference(\/.*)?/.test(pathname)) {
// path /doc/commands-reference... -> /doc/command-reference...
res.writeHead(301, {
Location: req.url.replace('commands-reference', 'command-reference')
})
res.end()
} else if (/^\/doc\/tutorial\/(.*)?/.test(pathname)) {
// path /doc/tutorial/... -> /doc/tutorials/deep/...
res.writeHead(301, {
Location: req.url.replace('/doc/tutorial/', '/doc/tutorials/deep/')
})
res.end()
} else if (pathname === '/doc/tutorial' || pathname === '/doc/tutorial/') {
// path /doc/tutorial -> /doc/tutorials
res.writeHead(301, {
Expand All @@ -75,12 +94,6 @@ app.prepare().then(() => {
)
})
res.end()
} else if (/^\/doc\/tutorial\/(.*)?/.test(pathname)) {
// path /doc/tutorial/... -> /doc/tutorials/deep/...
res.writeHead(301, {
Location: req.url.replace('/doc/tutorial/', '/doc/tutorials/deep/')
})
res.end()
} else if (/^\/doc.*/i.test(pathname)) {
// path /doc*/... -> /doc/...
let normalized_pathname = pathname.replace(/^\/doc[^?\/]*/i, '/doc')
Expand All @@ -95,18 +108,6 @@ app.prepare().then(() => {
} else {
app.render(req, res, '/doc', query)
}
} else if (/^\/(deb|rpm)\/.*/i.test(pathname)) {
// dvc.org/(deb|rpm) -> corresponding S3 bucket
res.writeHead(301, {
Location:
'https://s3-us-east-2.amazonaws.com/dvc-s3-repo/' +
pathname.substring(1)
})
res.end()
} else if (/^\/(help|chat)\/?$/i.test(pathname)) {
// dvc.org/(help|chat) -> Discord chat
res.writeHead(301, { Location: 'https://discordapp.com/invite/dvwXA2N' })
res.end()
} else {
handle(req, res, parsedUrl)
}
Expand Down

0 comments on commit e0c2de3

Please sign in to comment.