Skip to content

Instantly share code, notes, and snippets.

@centminmod
Forked from niedbalski/default.vcl
Created December 21, 2013 17:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save centminmod/8072101 to your computer and use it in GitHub Desktop.
# Varnish VCL file for Ghost blogging platform.
# http://ghost.org/
#
# Written for Ghost v0.3.0.
backend default {
.host = "blog-jniedbalski.rhcloud.com";
.port = "80";
}
sub vcl_recv {
if (req.request == "PURGE") {
return (lookup);
}
set req.http.host = "blog-jniedbalski.rhcloud.com";
set req.http.x-pass = "false";
if (req.url ~ "^/(api|signout)") {
set req.http.x-pass = "true";
} elseif (req.url ~ "^/ghost" && (req.url !~ "^/ghost/(img|css|fonts)")) {
set req.http.x-pass = "true";
}
if (req.http.x-pass == "true") {
return(pass);
}
unset req.http.cookie;
}
sub vcl_hit {
if (req.request == "PURGE") {
ban("req.url == " + req.url);
error 200 "Purged.";
}
}
sub vcl_miss {
if (req.request == "PURGE") {
ban("req.url == " + req.url);
error 200 "Purged.";
}
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
}
sub vcl_fetch {
# Only modify cookies/ttl outside of the management interface.
if (req.http.x-pass != "true") {
unset beresp.http.set-cookie;
if (beresp.status < 500 && beresp.ttl == 0s) {
set beresp.ttl = 1w;
set beresp.http.X-Cacheable = "YES";
}
}
}
diff --git a/a b/a
new file mode 100644
index 0000000..e69de29
diff --git a/core/server/api.js b/core/server/api.js
index 3c7270e..fd7f7bb 100644
--- a/core/server/api.js
+++ b/core/server/api.js
@@ -4,6 +4,7 @@
var Ghost = require('../ghost'),
_ = require('underscore'),
when = require('when'),
+ request = require('request'),
errors = require('./errorHandling'),
permissions = require('./permissions'),
canThis = permissions.canThis,
@@ -62,8 +63,18 @@ posts = {
});
},
- // #### Edit
+ varnishPurge: function remove(url) {
+ var urls = [ '/' + url, '/' ];
+
+ for(i = 0; i < urls.length; i++) {
+ request({
+ method: 'PURGE',
+ uri: "http://www.metaklass.org" + urls[i]
+ });
+ }
+ },
+ // #### Edit
// **takes:** a json object with all the properties which should be updated
edit: function edit(postData) {
// **returns:** a promise for the resulting post in a json object
@@ -72,7 +83,9 @@ posts = {
}
return canThis(this.user).edit.post(postData.id).then(function () {
- return dataProvider.Post.edit(postData);
+ post = dataProvider.Post.edit(postData);
+ posts.varnishPurge(postData.slug);
+ return post;
}, function () {
return when.reject("You do not have permission to edit this post.");
});
@@ -88,7 +101,9 @@ posts = {
}
return canThis(this.user).create.post().then(function () {
- return dataProvider.Post.add(postData);
+ post = dataProvider.Post.add(postData);
+ posts.varnishPurge(postData.slug);
+ return post;
}, function () {
return when.reject("You do not have permission to add posts.");
});
@@ -106,6 +121,7 @@ posts = {
return canThis(this.user).remove.post(args.id).then(function () {
return when(posts.read({id : args.id})).then(function (result) {
return dataProvider.Post.destroy(args.id).then(function () {
+ posts.varnishPurge(result.slug);
var deletedObj = {};
deletedObj.id = result.id;
deletedObj.slug = result.slug;
diff --git a/package.json b/package.json
index 7233705..8f9613c 100644
--- a/package.json
+++ b/package.json
@@ -18,6 +18,7 @@
"underscore": "1.5.1",
"showdown": "0.3.1",
"sqlite3": "2.1.16",
+ "request": "latest",
"bookshelf": "0.5.7",
"knex": "0.4.11",
"when": "2.2.1",
diff --git a/test b/test
new file mode 100644
index 0000000..e69de29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment