apostrophe-redirects
Advanced tools
Comparing version 0.6.4 to 0.6.5
43
index.js
@@ -34,3 +34,3 @@ module.exports = { | ||
required: true | ||
}, | ||
}, | ||
{ | ||
@@ -43,3 +43,3 @@ // contextual: true to hide this property | ||
def: true, | ||
contextual: true | ||
contextual: true | ||
}, | ||
@@ -54,3 +54,3 @@ { | ||
] | ||
}, | ||
}, | ||
{ | ||
@@ -61,3 +61,3 @@ name: '_newPage', | ||
label: 'Page Title', | ||
idField: 'pageId', | ||
idField: 'pageId', | ||
filters: { | ||
@@ -69,3 +69,3 @@ projection: { slug: 1, title: 1 }, | ||
} | ||
}, | ||
}, | ||
{ | ||
@@ -87,3 +87,3 @@ name: 'externalUrl', | ||
'_newPage', | ||
'externalUrl', | ||
'externalUrl' | ||
] | ||
@@ -93,7 +93,5 @@ } | ||
construct: function(self, options) { | ||
var pages = self.apos.pages; | ||
self.beforeSave = function(req, doc, options, callback) { | ||
//prefix the actual slug so it's not treated as a page | ||
construct: function (self, options) { | ||
self.beforeSave = function (req, doc, options, callback) { | ||
// prefix the actual slug so it's not treated as a page | ||
doc.slug = 'redirect-' + doc.redirectSlug; | ||
@@ -108,8 +106,6 @@ | ||
// ALL pages should check to see if a redirect exists | ||
var superPagesServe = pages.serve; | ||
pages.serve = function(req, res) { | ||
// req.url rather than req.params[0], lets us match query strings | ||
// Check to see if a redirect exists before sending user on their way | ||
self.expressMiddleware = function (req, res, next) { | ||
var slug = req.url; | ||
return self.find(req, { slug: 'redirect-' + slug }, { | ||
return self.find(req, { slug: 'redirect-' + slug }, { | ||
title: 1, | ||
@@ -123,14 +119,17 @@ slug: 1, | ||
_newPage: 1 | ||
}).toObject(function(err, result) { | ||
if(result) { | ||
if(result.urlType == 'internal' && result._newPage) { | ||
}).toObject(function (err, result) { | ||
if (err) { | ||
console.log(err); | ||
} | ||
if (result) { | ||
if (result.urlType === 'internal' && result._newPage) { | ||
return req.res.redirect(result._newPage.slug); | ||
} else if(result.urlType == 'external' && result.externalUrl.length) { | ||
} else if (result.urlType === 'external' && result.externalUrl.length) { | ||
return req.res.redirect(result.externalUrl); | ||
} | ||
} | ||
return superPagesServe(req, res); | ||
return next(); | ||
}); | ||
}; | ||
} | ||
} | ||
}; |
{ | ||
"name": "apostrophe-redirects", | ||
"version": "0.6.4", | ||
"version": "0.6.5", | ||
"description": "Allows admins to create redirects within an Apostrophe site", | ||
@@ -23,4 +23,12 @@ "main": "index.js", | ||
}, | ||
"dependencies": { | ||
"devDependencies": { | ||
"eslint": "^4.2.0", | ||
"eslint-config-punkave": "^1.0.8", | ||
"eslint-config-standard": "^10.2.1", | ||
"eslint-plugin-import": "^2.7.0", | ||
"eslint-plugin-node": "^5.1.0", | ||
"eslint-plugin-promise": "^3.5.0", | ||
"eslint-plugin-react": "^7.1.0", | ||
"eslint-plugin-standard": "^3.0.1" | ||
} | ||
} |
@@ -40,5 +40,6 @@ This module allows admins to add redirects from one URL to another within an [Apostrophe site](http://apostrophecms.org/). | ||
0.6.5: Use express middleware instead of relying on `apos.pages.serve`. This lets redirects happen for files, etc. | ||
0.6.1: the `redirectSlug` should be `type: 'string'` because the old site may have allowed nonsense in slugs that we do not allow. Also compare to `req.url` so query string matches are allowed. | ||
0.6.0: initial release. | ||
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
6005
5
45
8
1