mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Disable caching of API requests via middleware
Added a simple middleware to the api routes that disables caching via headers.
This commit is contained in:
parent
e953aac252
commit
8099396062
1 changed files with 18 additions and 8 deletions
26
app.js
26
app.js
|
@ -22,6 +22,7 @@
|
||||||
auth,
|
auth,
|
||||||
authAPI,
|
authAPI,
|
||||||
ghostLocals,
|
ghostLocals,
|
||||||
|
disableCachedResult,
|
||||||
|
|
||||||
// ## Variables
|
// ## Variables
|
||||||
loading = when.defer(),
|
loading = when.defer(),
|
||||||
|
@ -101,6 +102,15 @@
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
disableCachedResult = function (req, res, next) {
|
||||||
|
res.set({
|
||||||
|
"Cache-Control": "no-cache, must-revalidate",
|
||||||
|
"Expires": "Sat, 26 Jul 1997 05:00:00 GMT"
|
||||||
|
});
|
||||||
|
|
||||||
|
next();
|
||||||
|
};
|
||||||
|
|
||||||
// Expose the promise we will resolve after our pre-loading
|
// Expose the promise we will resolve after our pre-loading
|
||||||
ghost.loaded = loading.promise;
|
ghost.loaded = loading.promise;
|
||||||
|
|
||||||
|
@ -113,14 +123,14 @@
|
||||||
* API routes..
|
* API routes..
|
||||||
* @todo auth should be public auth not user auth
|
* @todo auth should be public auth not user auth
|
||||||
*/
|
*/
|
||||||
ghost.app().get('/api/v0.1/posts', authAPI, api.requestHandler(api.posts.browse));
|
ghost.app().get('/api/v0.1/posts', authAPI, disableCachedResult, api.requestHandler(api.posts.browse));
|
||||||
ghost.app().post('/api/v0.1/posts', authAPI, api.requestHandler(api.posts.add));
|
ghost.app().post('/api/v0.1/posts', authAPI, disableCachedResult, api.requestHandler(api.posts.add));
|
||||||
ghost.app().get('/api/v0.1/posts/:id', authAPI, api.requestHandler(api.posts.read));
|
ghost.app().get('/api/v0.1/posts/:id', authAPI, disableCachedResult, api.requestHandler(api.posts.read));
|
||||||
ghost.app().put('/api/v0.1/posts/:id', authAPI, api.requestHandler(api.posts.edit));
|
ghost.app().put('/api/v0.1/posts/:id', authAPI, disableCachedResult, api.requestHandler(api.posts.edit));
|
||||||
ghost.app().del('/api/v0.1/posts/:id', authAPI, api.requestHandler(api.posts.destroy));
|
ghost.app().del('/api/v0.1/posts/:id', authAPI, disableCachedResult, api.requestHandler(api.posts.destroy));
|
||||||
ghost.app().get('/api/v0.1/settings', authAPI, api.cachedSettingsRequestHandler(api.settings.browse));
|
ghost.app().get('/api/v0.1/settings', authAPI, disableCachedResult, api.cachedSettingsRequestHandler(api.settings.browse));
|
||||||
ghost.app().get('/api/v0.1/settings/:key', authAPI, api.cachedSettingsRequestHandler(api.settings.read));
|
ghost.app().get('/api/v0.1/settings/:key', authAPI, disableCachedResult, api.cachedSettingsRequestHandler(api.settings.read));
|
||||||
ghost.app().put('/api/v0.1/settings', authAPI, api.cachedSettingsRequestHandler(api.settings.edit));
|
ghost.app().put('/api/v0.1/settings', authAPI, disableCachedResult, api.cachedSettingsRequestHandler(api.settings.edit));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Admin routes..
|
* Admin routes..
|
||||||
|
|
Loading…
Add table
Reference in a new issue