ghost 4.17.0 → 4.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,6 +4,7 @@ const errors = require('@tryghost/errors');
|
|
|
4
4
|
|
|
5
5
|
const messages = {
|
|
6
6
|
redirectsWrongFormat: 'Incorrect redirects file format.',
|
|
7
|
+
invalidRedirectsFromRegex: 'Incorrect RegEx in redirects file.',
|
|
7
8
|
redirectsHelp: 'https://ghost.org/docs/themes/routing/#redirects'
|
|
8
9
|
};
|
|
9
10
|
/**
|
|
@@ -26,6 +27,17 @@ const validate = (redirects) => {
|
|
|
26
27
|
help: tpl(messages.redirectsHelp)
|
|
27
28
|
});
|
|
28
29
|
}
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
// each 'from' property should be a valid RegExp string
|
|
33
|
+
new RegExp(redirect.from);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
throw new errors.ValidationError({
|
|
36
|
+
message: tpl(messages.invalidRedirectsFromRegex),
|
|
37
|
+
context: redirect,
|
|
38
|
+
help: tpl(messages.redirectsHelp)
|
|
39
|
+
});
|
|
40
|
+
}
|
|
29
41
|
});
|
|
30
42
|
};
|
|
31
43
|
|
|
@@ -19,14 +19,14 @@ let customRedirectsRouter;
|
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
*
|
|
22
|
+
* @param {Object} router instance of Express Router to decorate with redirects
|
|
22
23
|
* @param {Object} redirects valid redirects JSON
|
|
24
|
+
*
|
|
23
25
|
* @returns {Object} instance of express.Router express router handling redirects based on config
|
|
24
26
|
*/
|
|
25
|
-
_private.registerRoutes = (redirects) => {
|
|
27
|
+
_private.registerRoutes = (router, redirects) => {
|
|
26
28
|
debug('redirects loading');
|
|
27
29
|
|
|
28
|
-
const redirectsRouter = express.Router('redirects');
|
|
29
|
-
|
|
30
30
|
if (labsService.isSet('offers')) {
|
|
31
31
|
redirects.unshift({
|
|
32
32
|
from: '/zimo50',
|
|
@@ -61,7 +61,7 @@ _private.registerRoutes = (redirects) => {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
debug('register', redirect.from);
|
|
64
|
-
|
|
64
|
+
router.get(new RegExp(redirect.from, options), function (req, res) {
|
|
65
65
|
const maxAge = redirect.permanent ? config.get('caching:customRedirects:maxAge') : 0;
|
|
66
66
|
const toURL = url.parse(redirect.to);
|
|
67
67
|
const toURLParams = querystring.parse(toURL.query);
|
|
@@ -91,16 +91,17 @@ _private.registerRoutes = (redirects) => {
|
|
|
91
91
|
|
|
92
92
|
debug('redirects loaded');
|
|
93
93
|
|
|
94
|
-
return
|
|
94
|
+
return router;
|
|
95
95
|
};
|
|
96
96
|
|
|
97
97
|
const loadRoutes = () => {
|
|
98
98
|
try {
|
|
99
|
+
customRedirectsRouter = express.Router('redirects');
|
|
100
|
+
|
|
99
101
|
const redirects = redirectsService.loadRedirectsFile();
|
|
100
102
|
redirectsService.validate(redirects);
|
|
101
103
|
|
|
102
|
-
|
|
103
|
-
customRedirectsRouter = redirectsRouter;
|
|
104
|
+
_private.registerRoutes(customRedirectsRouter, redirects);
|
|
104
105
|
} catch (err) {
|
|
105
106
|
if (errors.utils.isIgnitionError(err)) {
|
|
106
107
|
logging.error(err);
|