mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-15 03:01:37 -05:00
Simplified redirects module api
refs https://linear.app/tryghost/issue/CORE-35/refactor-route-and-redirect-settings - Made clear distinction around the methods that are exposed for the API use and for the internal use. Same pattern can be found in themese's module API
This commit is contained in:
parent
8bda544411
commit
8b6a2bb87f
5 changed files with 24 additions and 18 deletions
|
@ -11,7 +11,7 @@ module.exports = {
|
|||
disposition: {
|
||||
type: 'file',
|
||||
value() {
|
||||
return redirects.settings.getRedirectsFilePath()
|
||||
return redirects.api.getRedirectsFilePath()
|
||||
.then((filePath) => {
|
||||
// TODO: Default file type is .json for backward compatibility.
|
||||
// When .yaml becomes default or .json is removed at v4,
|
||||
|
@ -26,13 +26,13 @@ module.exports = {
|
|||
permissions: true,
|
||||
response: {
|
||||
async format() {
|
||||
const filePath = await redirects.settings.getRedirectsFilePath();
|
||||
const filePath = await redirects.api.getRedirectsFilePath();
|
||||
|
||||
return filePath === null || path.extname(filePath) === '.json' ? 'json' : 'plain';
|
||||
}
|
||||
},
|
||||
query() {
|
||||
return redirects.settings.get();
|
||||
return redirects.api.get();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -42,7 +42,7 @@ module.exports = {
|
|||
cacheInvalidate: true
|
||||
},
|
||||
query(frame) {
|
||||
return redirects.settings.setFromFilePath(frame.file.path, frame.file.ext)
|
||||
return redirects.api.setFromFilePath(frame.file.path, frame.file.ext)
|
||||
.then(() => {
|
||||
// CASE: trigger that redirects are getting re-registered
|
||||
web.shared.middlewares.customRedirects.reload();
|
||||
|
|
|
@ -13,7 +13,7 @@ module.exports = {
|
|||
},
|
||||
permissions: true,
|
||||
query() {
|
||||
return redirects.settings.get();
|
||||
return redirects.api.get();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -23,7 +23,7 @@ module.exports = {
|
|||
cacheInvalidate: true
|
||||
},
|
||||
query(frame) {
|
||||
return redirects.settings.setFromFilePath(frame.file.path)
|
||||
return redirects.api.setFromFilePath(frame.file.path)
|
||||
.then(() => {
|
||||
// CASE: trigger that redirects are getting re-registered
|
||||
web.shared.middlewares.customRedirects.reload();
|
||||
|
|
|
@ -11,7 +11,7 @@ module.exports = {
|
|||
disposition: {
|
||||
type: 'file',
|
||||
value() {
|
||||
return redirects.settings.getRedirectsFilePath()
|
||||
return redirects.api.getRedirectsFilePath()
|
||||
.then((filePath) => {
|
||||
// TODO: Default file type is .json for backward compatibility.
|
||||
// When .yaml becomes default or .json is removed at v4,
|
||||
|
@ -26,13 +26,13 @@ module.exports = {
|
|||
permissions: true,
|
||||
response: {
|
||||
async format() {
|
||||
const filePath = await redirects.settings.getRedirectsFilePath();
|
||||
const filePath = await redirects.api.getRedirectsFilePath();
|
||||
|
||||
return filePath === null || path.extname(filePath) === '.json' ? 'json' : 'plain';
|
||||
}
|
||||
},
|
||||
query() {
|
||||
return redirects.settings.get();
|
||||
return redirects.api.get();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -42,7 +42,7 @@ module.exports = {
|
|||
cacheInvalidate: true
|
||||
},
|
||||
query(frame) {
|
||||
return redirects.settings.setFromFilePath(frame.file.path, frame.file.ext)
|
||||
return redirects.api.setFromFilePath(frame.file.path, frame.file.ext)
|
||||
.then(() => {
|
||||
// CASE: trigger that redirects are getting re-registered
|
||||
web.shared.middlewares.customRedirects.reload();
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
module.exports = {
|
||||
get settings() {
|
||||
return require('./settings');
|
||||
},
|
||||
const settings = require('./settings');
|
||||
const validation = require('./validation');
|
||||
|
||||
get validation() {
|
||||
return require('./validation');
|
||||
module.exports = {
|
||||
loadRedirectsFile: settings.loadRedirectsFile,
|
||||
validate: validation.validate,
|
||||
/**
|
||||
* Methods used in the API
|
||||
*/
|
||||
api: {
|
||||
getRedirectsFilePath: settings.getRedirectsFilePath,
|
||||
get: settings.get,
|
||||
setFromFilePath: settings.setFromFilePath
|
||||
}
|
||||
};
|
||||
|
|
|
@ -19,9 +19,9 @@ _private.registerRoutes = () => {
|
|||
customRedirectsRouter = express.Router('redirects');
|
||||
|
||||
try {
|
||||
const redirects = redirectsService.settings.loadRedirectsFile();
|
||||
const redirects = redirectsService.loadRedirectsFile();
|
||||
|
||||
redirectsService.validation.validate(redirects);
|
||||
redirectsService.validate(redirects);
|
||||
|
||||
redirects.forEach((redirect) => {
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue