Skip to content

Commit

Permalink
move a conditional to the handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash committed Jul 17, 2024
1 parent f16a432 commit 91f5a85
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
22 changes: 16 additions & 6 deletions server/routes/alerts-and-warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ async function routeHandler (request, h) {
return h.view(route, { model })
}

if (isLocationEngland(location)) {
return h.redirect(`/${route}`)
}

const [place] = await locationService.find(location)

if (!place) {
Expand Down Expand Up @@ -111,7 +107,15 @@ async function locationRouteHandler (request, h) {
module.exports = [{
method: 'GET',
path: `/${route}`,
handler: routeHandler,
handler: (request, h) => {
if (request.query.q) {
if (isLocationEngland(util.cleanseLocation(request.query.q))) {
return h.redirect(`/${route}`)
}
}

return routeHandler(request, h)
},
options: {
validate: {
query: joi.object({
Expand Down Expand Up @@ -151,7 +155,13 @@ module.exports = [{
{
method: 'POST',
path: `/${route}`,
handler: routeHandler,
handler: (request, h) => {
if (isLocationEngland(util.cleanseLocation(request.payload.location))) {
return h.redirect(`/${route}`)
}

return routeHandler(request, h)
},
options: {
validate: {
payload: joi.object({
Expand Down
12 changes: 11 additions & 1 deletion server/routes/river-and-sea-levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ module.exports = [{
// note: the redirects below are to handle any bookmarks users may have as all internal links use the new format
// the redirects can be removed at some point in the future when we are no longer concerned about broken bookmarks
if (request.query.q) {
if (isLocationEngland(util.cleanseLocation(request.query.q))) {
return h.redirect(`/${route}`)
}

return locationQueryHandler(request, h)
}
if (rainfallid) {
Expand Down Expand Up @@ -271,7 +275,13 @@ module.exports = [{
}, {
method: 'POST',
path: `/${route}`,
handler: locationQueryHandler,
handler: (request, h) => {
if (isLocationEngland(util.cleanseLocation(request.payload.location))) {
return h.redirect(`/${route}`)
}

return locationQueryHandler(request, h)
},
options: {
validate: {
payload: joi.object({
Expand Down

0 comments on commit 91f5a85

Please sign in to comment.