odania 0.0.16 → 0.0.17

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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +63 -21
  3. data/Guardfile +31 -0
  4. data/Rakefile +1 -0
  5. data/config/varnish_config.json +4 -2
  6. data/lib/odania/{plugin_config/models → config}/backend.rb +1 -1
  7. data/lib/odania/{plugin_config/models → config}/backend_group.rb +7 -2
  8. data/lib/odania/config/domain.rb +55 -0
  9. data/lib/odania/config/duplicates.rb +28 -0
  10. data/lib/odania/config/global_config.rb +154 -0
  11. data/lib/odania/config/internal.rb +48 -0
  12. data/lib/odania/config/layout.rb +35 -0
  13. data/lib/odania/config/page.rb +28 -0
  14. data/lib/odania/config/plugin_config.rb +51 -0
  15. data/lib/odania/config/style.rb +60 -0
  16. data/lib/odania/config/sub_domain.rb +125 -0
  17. data/lib/odania/config.rb +16 -0
  18. data/lib/odania/consul.rb +6 -2
  19. data/lib/odania/erb.rb +154 -0
  20. data/lib/odania/plugin.rb +12 -5
  21. data/lib/odania/plugin_config/{plugin_config.rb → base.rb} +26 -31
  22. data/lib/odania/varnish/generators/generate_backend_vcl.rb +12 -0
  23. data/lib/odania/varnish/generators/generate_site_vcl.rb +16 -0
  24. data/lib/odania/varnish/generators/generate_sites_vcl.rb +0 -4
  25. data/lib/odania/varnish.rb +11 -12
  26. data/lib/odania/version.rb +1 -1
  27. data/lib/odania.rb +7 -1
  28. data/odania.gemspec +3 -0
  29. data/spec/fixtures/global_config.json +142 -0
  30. data/spec/fixtures/plugin_config_1.json +93 -0
  31. data/spec/lib/odania/config/global_config_spec.rb +67 -0
  32. data/spec/lib/odania/config/plugin_config_spec.rb +28 -0
  33. data/spec/lib/odania/erb_spec.rb +16 -0
  34. data/spec/lib/odania/plugin_spec.rb +25 -0
  35. data/spec/lib/odania/varnish_spec.rb +37 -0
  36. data/spec/spec_helper.rb +15 -0
  37. data/spec/support/consul_mock.rb +116 -0
  38. data/tasks/odania.rake +1 -5
  39. data/templates/varnish/backend.vcl.erb +7 -1
  40. data/templates/varnish/catch_all.vcl.erb +1 -0
  41. data/templates/varnish/default.vcl.erb +1 -0
  42. data/templates/varnish/general.vcl.erb +29 -13
  43. data/templates/varnish/general_site.vcl.erb +33 -0
  44. data/templates/varnish/redirects.vcl.erb +1 -0
  45. data/templates/varnish/site.vcl.erb +18 -8
  46. data/templates/varnish/sites.vcl.erb +1 -1
  47. data/templates/varnish/websocker.vcl.erb +1 -0
  48. metadata +79 -19
  49. data/lib/odania/plugin_config/models/domain.rb +0 -38
  50. data/lib/odania/plugin_config/models/layout.rb +0 -31
  51. data/lib/odania/plugin_config/models/page.rb +0 -23
  52. data/lib/odania/plugin_config/models/redirect.rb +0 -20
  53. data/lib/odania/plugin_config/models/sub_domain.rb +0 -99
  54. data/lib/odania/template/asset.rb +0 -15
  55. data/lib/odania/template/config.rb +0 -15
  56. data/lib/odania/template/page.rb +0 -16
  57. data/lib/odania/template.rb +0 -8
  58. data/lib/odania/varnish/generators/generate_site_assets_vcl.rb +0 -27
  59. data/templates/varnish/site_assets.vcl.erb +0 -24
  60. /data/spec/{odania → lib}/odania_spec.rb +0 -0
@@ -0,0 +1,142 @@
1
+ {
2
+ "config": {
3
+ "title": "This is my awesome title",
4
+ "default_backend_groups": [
5
+ "odania-static"
6
+ ]
7
+ },
8
+ "plugin-config": {
9
+ "odania-static": {
10
+ "name": "odania-core",
11
+ "default": true,
12
+ "author": [
13
+ "Mike Petersen <mike@odania-it.com>"
14
+ ],
15
+ "url": "http://www.odania.com",
16
+ "sites": [
17
+ "www.domain.de"
18
+ ]
19
+ }
20
+ },
21
+ "default_subdomains": {
22
+ "_general": "www"
23
+ },
24
+ "domains": {
25
+ "_general": {
26
+ "_general": {
27
+ "config": {
28
+ },
29
+ "redirects": {
30
+ "odania.com$": "www.odania.com",
31
+ "odania.de$": "www.odania.com/de"
32
+ },
33
+ "internal": {
34
+ "layouts": {
35
+ },
36
+ "partials": {
37
+ }
38
+ }
39
+ }
40
+ },
41
+ "example.com": {
42
+ "_general": {
43
+ "config": {
44
+ },
45
+ "direct": {
46
+ "/imprint": {
47
+ "group_name": "static-content",
48
+ "plugin_url": "/contents/my-awesome-imprint"
49
+ }
50
+ },
51
+ "internal": {
52
+ "layouts": {
53
+ },
54
+ "partials": {
55
+ }
56
+ }
57
+ },
58
+ "www": {
59
+ "dynamic": {
60
+ "/de/openhab/2015-09-17-testing-openhab2": {
61
+ "group_name": "static-content",
62
+ "plugin_url": "/contents/www.example.com/web/de/openhab/2015-09-17-testing-openhab2.html",
63
+ "cacheable": true,
64
+ "expires": 60
65
+ },
66
+ "/de": {
67
+ "group_name": "static-content",
68
+ "plugin_url": "/contents/www.example.com/web/de/index.html"
69
+ }
70
+ },
71
+ "direct": {
72
+ "/favicon.ico": {
73
+ "group_name": "odania-core",
74
+ "plugin_url": "/admin/favicon.ico"
75
+ },
76
+ "/assets/admin/js/admin.js": {
77
+ "group_name": "odania-core",
78
+ "plugin_url": "/assets/admin/js/admin.js"
79
+ },
80
+ "hamster.jpeg": {
81
+ "group_name": "static-content",
82
+ "plugin_url": "/contents/www.example.com/assets/hamster.jpeg"
83
+ },
84
+ "imprint": {
85
+ "group_name": "static-content",
86
+ "plugin_url": "/contents/my-special-imprint"
87
+ }
88
+ },
89
+ "internal": {
90
+ "layouts": {
91
+ "main": {
92
+ "styles": {
93
+ "_general": {
94
+ "entry_point": "application.html.erb",
95
+ "direct": {
96
+ "layouts/mac-beath/img/favicon/favicon.png": {
97
+ "group_name": "static-content",
98
+ "plugin_url": "layouts/mac-beath/img/favicon/favicon.png",
99
+ "cacheable": true,
100
+ "expires": 60
101
+ },
102
+ "layouts/mac-beath/img/photos/t12.jpg": {
103
+ "group_name": "static-content",
104
+ "plugin_url": "layouts/mac-beath/img/photos/t12.jpg"
105
+ }
106
+ },
107
+ "dynamic": {
108
+ "layouts/simple/application_part1.html": {
109
+ "group_name": "static-content",
110
+ "plugin_url": "layouts/simple/application_part1.html.erb",
111
+ "cacheable": true,
112
+ "expires": 60
113
+ }
114
+ }
115
+ },
116
+ "left_menu": {
117
+ "entry_point": "application.html.erb",
118
+ "direct": {},
119
+ "dynamic": {}
120
+ }
121
+ }
122
+ }
123
+ },
124
+ "partials": {
125
+ "footer": {
126
+ "name": "footer",
127
+ "group_name": "static-content",
128
+ "plugin_url": "partials/footer.html",
129
+ "cacheable": true,
130
+ "expires": 60
131
+ },
132
+ "tracking": {
133
+ "name": "tracking",
134
+ "group_name": "static-content",
135
+ "plugin_url": "partials/tracking.html"
136
+ }
137
+ }
138
+ }
139
+ }
140
+ }
141
+ }
142
+ }
@@ -0,0 +1,93 @@
1
+ {
2
+ "plugin-config": {
3
+ "name": "odania-core",
4
+ "default": true,
5
+ "author": [
6
+ "Mike Petersen <mike@odania-it.com>"
7
+ ],
8
+ "url": "http://www.odania.com",
9
+ "sites": [
10
+ "www.domain.de"
11
+ ]
12
+ },
13
+ "config": {
14
+ "title": "This is my awesome title"
15
+ },
16
+ "default_subdomains": {
17
+ "_general": "www"
18
+ },
19
+ "domains": {
20
+ "_general": {
21
+ "_general": {
22
+ "redirects": {},
23
+ "config": {},
24
+ "direct": {},
25
+ "dynamic": {},
26
+ "internal": {
27
+ "layouts": {
28
+ "main": {
29
+ "styles": {
30
+ "_general": {
31
+ "entry_point": "application.html.erb",
32
+ "direct": {
33
+ "layouts/mac-beath/img/favicon/favicon.png": {
34
+ "plugin_url": "layouts/mac-beath/img/favicon/favicon.png",
35
+ "cacheable": true,
36
+ "expires": 60
37
+ },
38
+ "layouts/mac-beath/img/photos/t12.jpg": {
39
+ "plugin_url": "layouts/mac-beath/img/photos/t12.jpg"
40
+ }
41
+ },
42
+ "dynamic": {
43
+ "layouts/simple/application_part1.html": {
44
+ "plugin_url": "layouts/simple/application_part1.html.erb",
45
+ "cacheable": true,
46
+ "expires": 60
47
+ }
48
+ }
49
+ },
50
+ "left_menu": {
51
+ "entry_point": "application.html.erb",
52
+ "direct": {},
53
+ "dynamic": {}
54
+ }
55
+ }
56
+ }
57
+ },
58
+ "partials": {
59
+ "footer": {
60
+ "plugin_url": "partials/footer.html",
61
+ "cacheable": true,
62
+ "expires": 60
63
+ }
64
+ }
65
+ }
66
+ }
67
+ },
68
+ "example.com": {
69
+ "www": {
70
+ "redirects": {
71
+ "^/test": "/test2"
72
+ },
73
+ "config": {},
74
+ "direct": {
75
+ "/imprint": {
76
+ "plugin_url": "/my-imprint",
77
+ "cacheable": true,
78
+ "expires": 60
79
+ },
80
+ "/": {
81
+ "plugin_url": "/my-home",
82
+ "cacheable": false
83
+ }
84
+ },
85
+ "dynamic": {},
86
+ "internal": {
87
+ "layouts": {},
88
+ "partials": {}
89
+ }
90
+ }
91
+ }
92
+ }
93
+ }
@@ -0,0 +1,67 @@
1
+ describe Odania::Config::GlobalConfig do
2
+ let(:cfg1) {
3
+ JSON.parse File.read("#{BASE_DIR}/spec/fixtures/plugin_config_1.json")
4
+ }
5
+ let(:global_cfg) {
6
+ JSON.parse File.read("#{BASE_DIR}/spec/fixtures/global_config.json")
7
+ }
8
+
9
+ context 'configuration' do
10
+ it 'add configuration' do
11
+ expect(subject.add_plugin_config(cfg1)).to be(true)
12
+
13
+ cfg_result = subject.dump
14
+ expect(cfg_result['domains']['example.com']['www']['redirects']).to eql(cfg1['domains']['example.com']['www']['redirects'])
15
+ expect(cfg_result['domains']['example.com']['www']['config']).to eql(cfg1['domains']['example.com']['www']['config'])
16
+
17
+ cfg1['domains']['example.com']['www']['direct'].each_pair do |path, data|
18
+
19
+ expect(cfg_result['domains']['example.com']['www']['direct'][path]['plugin_url']).to eql(data['plugin_url'])
20
+ end
21
+
22
+ end
23
+
24
+ it 'detects duplicates' do
25
+ expect(subject.add_plugin_config(cfg1)).to be(true)
26
+ expect(subject.duplicates).to be_empty
27
+ expect(subject.add_plugin_config(cfg1)).to be(true)
28
+
29
+ duplicates = subject.duplicates
30
+ expect(subject.duplicates).not_to be_empty
31
+ expect(duplicates).to have_key(:config)
32
+ expect(duplicates).to have_key(:direct)
33
+ expect(duplicates).to have_key(:redirect)
34
+ end
35
+
36
+ it 'generate global configuration' do
37
+ cfg_name = cfg1['plugin-config']['name']
38
+ $consul_mock.config.set("plugins_config/#{cfg_name}", cfg1)
39
+
40
+ $consul_mock.service.services = {
41
+ cfg_name => [
42
+ OpenStruct.new({
43
+ 'Node' => 'agent-one',
44
+ 'Address' => '172.20.20.1',
45
+ 'ServiceID' => "#{cfg_name}_1",
46
+ 'ServiceName' => cfg_name,
47
+ 'ServiceTags' => [],
48
+ 'ServicePort' => 80,
49
+ 'ServiceAddress' => '172.20.20.1'
50
+ }),
51
+ OpenStruct.new({
52
+ 'Node' => 'agent-two',
53
+ 'Address' => '172.20.20.2',
54
+ 'ServiceID' => "#{cfg_name}_2",
55
+ 'ServiceName' => cfg_name,
56
+ 'ServiceTags' => [],
57
+ 'ServicePort' => 80,
58
+ 'ServiceAddress' => '172.20.20.1'
59
+ })
60
+ ]
61
+ }
62
+
63
+ global_config = subject.generate_global_config
64
+ expect(global_config).not_to be_empty
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,28 @@
1
+ describe Odania::Config::PluginConfig do
2
+ let(:cfg) {
3
+ JSON.parse File.read("#{BASE_DIR}/spec/fixtures/plugin_config_1.json")
4
+ }
5
+
6
+ context 'configuration' do
7
+ it 'should be valid' do
8
+ expect(subject.config).to be_a(Hash)
9
+ expect(subject.domains).to be_a(Hash)
10
+ subject.domains.each_pair do |domain, data|
11
+ expect(data).to be_a(Odania::Config::Domain)
12
+ end
13
+ end
14
+
15
+ it 'loads configuration' do
16
+ expect(subject.load(cfg)).to be(true)
17
+
18
+ expect(subject.config).to eql(cfg['config'])
19
+ expect(subject.plugin_config).to eql(cfg['plugin-config'])
20
+ expect(subject.domains.keys).to eql(cfg['domains'].keys)
21
+ end
22
+
23
+ it 'dumps the same config' do
24
+ expect(subject.load(cfg)).to be(true)
25
+ expect(subject.dump).to eql(cfg)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ describe Odania::Erb do
2
+ context 'render simple template' do
3
+ let(:subject) {
4
+ Odania::Erb.new('This is a very simple template', 'example.com', {}, 'odania-test', 'test.odania.com')
5
+ }
6
+
7
+ let(:global_cfg) {
8
+ JSON.parse File.read("#{BASE_DIR}/spec/fixtures/global_config.json")
9
+ }
10
+
11
+ it 'renders simple template' do
12
+ $consul_mock.config.set('global_plugins_config', global_cfg)
13
+ expect(subject.render).to eq('This is a very simple template')
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ describe Odania::Plugin do
2
+ context 'services' do
3
+ let(:subject) {
4
+ Odania::Plugin.new($consul_mock)
5
+ }
6
+
7
+ let(:cfg) {
8
+ JSON.parse File.read("#{BASE_DIR}/spec/fixtures/plugin_config_1.json")
9
+ }
10
+
11
+ it 'registers a plugin' do
12
+ cfg_name = cfg['plugin-config']['name']
13
+ instance_name = 'cfg_instance_1'
14
+ key_name = "#{cfg_name}|#{instance_name}"
15
+ expect(subject.register(instance_name, cfg)).to eql(key_name)
16
+ expect($consul_mock.configuration["plugins_config/#{cfg_name}"]).to eql(cfg)
17
+ end
18
+
19
+ it 'deregisters a plugin' do
20
+ instance_name = 'cfg_instance_1'
21
+ subject.register(instance_name, cfg)
22
+ expect(subject.deregister(instance_name)).to be_truthy
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,37 @@
1
+ describe Odania::Varnish do
2
+ context 'generate' do
3
+ before do
4
+ $consul_mock.service.services = {
5
+ 'odania_static' => [
6
+ OpenStruct.new({
7
+ 'Node' => 'agent-one',
8
+ 'Address' => '172.20.20.1',
9
+ 'ServiceID' => 'odania_static_1',
10
+ 'ServiceName' => 'odania_static',
11
+ 'ServiceTags' => [],
12
+ 'ServicePort' => 80,
13
+ 'ServiceAddress' => '172.20.20.1'
14
+ }),
15
+ OpenStruct.new({
16
+ 'Node' => 'agent-two',
17
+ 'Address' => '172.20.20.2',
18
+ 'ServiceID' => 'odania_static_2',
19
+ 'ServiceName' => 'odania_static',
20
+ 'ServiceTags' => [],
21
+ 'ServicePort' => 80,
22
+ 'ServiceAddress' => '172.20.20.1'
23
+ })
24
+ ]
25
+ }
26
+ end
27
+
28
+ let(:global_cfg) {
29
+ JSON.parse File.read("#{BASE_DIR}/spec/fixtures/global_config.json")
30
+ }
31
+
32
+ it 'generates the varnish config' do
33
+ $consul_mock.config.set('global_plugins_config', global_cfg)
34
+ expect(subject.generate('/tmp/varnish')).to eq('odania-varnish|odania_varnish_1')
35
+ end
36
+ end
37
+ end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,16 @@
1
+ ENV['ENVIRONMENT'] = 'test'
2
+
1
3
  require 'odania'
4
+ require_relative 'support/consul_mock'
5
+
6
+
7
+ RSpec.configure do |config|
8
+ config.before(:each) do
9
+ $consul_mock = ConsulMock.new
10
+
11
+
12
+ allow(Odania).to receive(:plugin) do
13
+ Odania::Plugin.new($consul_mock)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,116 @@
1
+ class ConsulMock < Odania::Consul
2
+ attr_reader :service, :config, :event, :health
3
+ attr_accessor :configuration
4
+
5
+ def initialize
6
+ self.configuration = {
7
+ 'global_plugins_config' => {
8
+ 'domains' => {}
9
+ }
10
+ }
11
+
12
+ @service = Service.new
13
+ @config = Config.new(self.configuration)
14
+ @event = Event.new
15
+ @health = Health.new
16
+ end
17
+
18
+ class Config
19
+ def initialize(configuration)
20
+ @configuration = configuration
21
+ end
22
+
23
+ def get(path)
24
+ @configuration[path]
25
+ end
26
+
27
+ def get_all(path)
28
+ result = {}
29
+ @configuration.each_pair do |key, value|
30
+ result[key] = value if key.start_with? path
31
+ end
32
+
33
+ result
34
+ end
35
+
36
+ def set(key, value)
37
+ @configuration[key] = value
38
+ end
39
+
40
+ def delete(key)
41
+ @configuration.delete[key]
42
+ end
43
+ end
44
+
45
+ class Service
46
+ attr_accessor :services
47
+
48
+ def initialize
49
+ @services = {}
50
+ end
51
+
52
+ def get_all
53
+ @services
54
+ end
55
+
56
+ def get_all_for(plugin_name)
57
+ result = []
58
+ @services.each_pair do |key, val|
59
+ result << val if key.start_with? plugin_name
60
+ end
61
+ result
62
+ end
63
+
64
+ def get(key, scope=:first)
65
+ @services[key]
66
+ end
67
+
68
+ def register(consul_config)
69
+ @services[consul_config['id']] = consul_config
70
+ end
71
+
72
+ def deregister(name)
73
+ @services.delete name
74
+ end
75
+
76
+ def build_config(plugin_name, plugin_instance_name, ip, tags=[], port=80)
77
+ {
78
+ 'id' => plugin_instance_name,
79
+ 'name' => plugin_name,
80
+ 'tags' => tags,
81
+ 'address' => ip,
82
+ 'port' => port,
83
+ 'token' => plugin_instance_name,
84
+ 'checks' => [
85
+ {
86
+ 'id' => plugin_name,
87
+ 'name' => "HTTP on port #{port}",
88
+ 'http' => "http://#{ip}:#{port}/health",
89
+ 'interval' => '10s',
90
+ 'timeout' => '1s'
91
+ }
92
+ ]
93
+ }
94
+ end
95
+ end
96
+
97
+ class Event
98
+ def initialize
99
+ @events = Hash.new { |hash, key| hash[key] = [] }
100
+ end
101
+
102
+ def fire(key, value)
103
+ @events[key] << value
104
+ end
105
+ end
106
+
107
+ class Health
108
+ def state(state=:any)
109
+ Diplomat::Health.state(state)
110
+ end
111
+
112
+ def service(name)
113
+ Diplomat::Health.service(name)
114
+ end
115
+ end
116
+ end
data/tasks/odania.rake CHANGED
@@ -2,11 +2,7 @@ namespace :odania do
2
2
  namespace :global do
3
3
  desc 'Generate the global config'
4
4
  task :generate_config do
5
- puts 'Loading plugin configs from consul'
6
- Odania.plugin.plugin_config.load_from_consul
7
-
8
- puts 'Generating global config'
9
- Odania.plugin.plugin_config.generate
5
+ Odania.plugin.plugin_config.generate_global_config
10
6
  end
11
7
  end
12
8
  end
@@ -1,5 +1,6 @@
1
1
  vcl 4.0;
2
2
  # generated varnish config: <%= ENVIRONMENT %>
3
+ # local test: <%= LOCAL_TEST_MODE ? 'ENABLED' : 'DISABLED' %>
3
4
 
4
5
  import std;
5
6
  import directors;
@@ -7,7 +8,7 @@ import directors;
7
8
  probe www_probe {
8
9
  .url = "/health";
9
10
  .timeout = 1s;
10
- .interval = 4s;
11
+ .interval = <%= LOCAL_TEST_MODE ? '60s' : '4s' %>;
11
12
  .window = 5;
12
13
  .threshold = 3;
13
14
  }
@@ -40,4 +41,9 @@ sub vcl_init {
40
41
  <%= Odania.varnish_sanitize(backend_group.name) %>_director.add_backend(<%= Odania.varnish_sanitize(group_name) %>_<%= Odania.varnish_sanitize(backend.instance_name) %>);
41
42
  <% end %>
42
43
  <% end %>
44
+
45
+ new core_backend_director = directors.round_robin();
46
+ <% core_backends.each do |core_backend_name| %>
47
+ core_backend_director.add_backend(<%= core_backend_name %>);
48
+ <% end %>
43
49
  }
@@ -1,4 +1,5 @@
1
1
  vcl 4.0;
2
2
  # generated varnish config: <%= ENVIRONMENT %>
3
+ # local test: <%= LOCAL_TEST_MODE ? 'ENABLED' : 'DISABLED' %>
3
4
 
4
5
  # Catch all
@@ -1,5 +1,6 @@
1
1
  vcl 4.0;
2
2
  # generated varnish config: <%= ENVIRONMENT %>
3
+ # local test: <%= LOCAL_TEST_MODE ? 'ENABLED' : 'DISABLED' %>
3
4
 
4
5
  sub vcl_synth {
5
6
  if (resp.status == 750) {
@@ -3,11 +3,27 @@
3
3
  %>
4
4
  vcl 4.0;
5
5
  # generated varnish config: <%= ENVIRONMENT %>
6
+ # local test: <%= LOCAL_TEST_MODE ? 'ENABLED' : 'DISABLED' %>
6
7
 
7
8
  ### Called when a client request is received
8
9
  sub vcl_recv {
10
+ ## Internal requests for content/partials
11
+ ## we use internal.core to not have this part open to public
12
+ if (req.http.host ~ "^internal.core$") {
13
+ if (req.url ~ "^/template/content") {
14
+ std.log("template content identified! Page:" + req.url);
15
+ set req.backend_hint = core_backend_director.backend();
16
+ return (hash);
17
+ } else if (req.url ~ "^/template/partial") {
18
+ std.log("template partial identified! Page:" + req.url);
19
+ set req.backend_hint = core_backend_director.backend();
20
+ return (hash);
21
+ }
22
+ }
23
+
9
24
  ### always cache these items:
10
25
 
26
+ # varnish is alive. Get health state from core plugin.
11
27
  if (req.url ~ "^/health$") {
12
28
  return (hash);
13
29
  }
@@ -17,25 +33,25 @@ sub vcl_recv {
17
33
  #}
18
34
 
19
35
  ## images
20
- if (req.method == "GET" && req.url ~ "\.(gif|jpg|jpeg|bmp|png|tiff|tif|ico|img|tga|wmf)$") {
21
- return (hash);
22
- }
36
+ #if (req.method == "GET" && req.url ~ "\.(gif|jpg|jpeg|bmp|png|tiff|tif|ico|img|tga|wmf)$") {
37
+ # return (hash);
38
+ #}
23
39
 
24
40
  ## various other content pages
25
- if (req.method == "GET" && req.url ~ "\.(css)$") {
26
- return (hash);
27
- }
41
+ #if (req.method == "GET" && req.url ~ "\.(css)$") {
42
+ # return (hash);
43
+ #}
28
44
 
29
45
  ## multimedia
30
- if (req.method == "GET" && req.url ~ "\.(svg|swf|ico|mp3|mp4|m4a|ogg|mov|avi|wmv)$") {
31
- return (hash);
32
- }
46
+ #if (req.method == "GET" && req.url ~ "\.(svg|swf|ico|mp3|mp4|m4a|ogg|mov|avi|wmv)$") {
47
+ # return (hash);
48
+ #}
33
49
 
34
50
  ## xml
35
51
 
36
- if (req.method == "GET" && req.url ~ "\.(xml)$") {
37
- return (hash);
38
- }
52
+ #if (req.method == "GET" && req.url ~ "\.(xml)$") {
53
+ # return (hash);
54
+ #}
39
55
  }
40
56
 
41
57
  ### Called when the requested object has been retrieved from the backend, or the request to the backend has failed
@@ -73,7 +89,7 @@ sub vcl_backend_response {
73
89
  set beresp.do_esi = true;
74
90
  set beresp.grace = 6h;
75
91
 
76
- <% unless ENVIRONMENT.eql?('production') %>
92
+ <% if LOCAL_TEST_MODE %>
77
93
  set beresp.ttl = 1s;
78
94
  <% end %>
79
95
  }