Skip to content

Commit

Permalink
Update to make VHOST or config/vhost.yml optional (fallback to develo…
Browse files Browse the repository at this point in the history
…pment mode)

Remove GEOMETRY_ALIAS feature for now (simplify)
Add default Cache-Control header; overwrite with your own DOWNLOAD_HEADERS
  • Loading branch information
choonkeat committed Apr 5, 2015
1 parent 370d6e5 commit 199ced9
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ The `paths` value should be delimited by the newline character, aka `\n`. In the

This allows a single attache server to be the workhorse for multiple different apps. Refer to `config/vhost.example.yml` file for configuration details.

At boot time, `attache` server will first look at `VHOST` environment variable. If that is missing, it will load the content of `config/vhost.yml`. Either one **MUST** exist.
At boot time, `attache` server will first look at `VHOST` environment variable. If that is missing, it will load the content of `config/vhost.yml`. If neither exist, the `attache` server run in development mode; uploaded files are only stored locally and may be evicted due to free space constraints.

If you do not want to write down sensitive information like access key and secrets into a `config/vhost.yml` file, you can convert the entire content into `json` format

```
```
ruby -ryaml -rjson -e 'puts YAML.load(IO.read("config/vhost.yml")).to_json'
```

Expand Down
2 changes: 1 addition & 1 deletion lib/attache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class << self

Attache.logger = Logger.new(STDOUT)
Attache.localdir = File.expand_path(ENV.fetch('LOCAL_DIR') { Dir.tmpdir })
Attache.vhost = JSON.parse(ENV.fetch('VHOST') { YAML.load(IO.read('config/vhost.yml')).to_json })
Attache.vhost = JSON.parse(ENV.fetch('VHOST') { YAML.load(IO.read('config/vhost.yml')).to_json rescue '{}' })
Attache.cache = DiskStore.new(Attache.localdir, {
cache_size: ENV.fetch('CACHE_SIZE_BYTES') {
stat = Sys::Filesystem.stat("/")
Expand Down
1 change: 0 additions & 1 deletion lib/attache/download.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ def _call(env, config)
case env['PATH_INFO']
when %r{\A/view/}
parse_path_info(env['PATH_INFO']['/view/'.length..-1]) do |dirname, geometry, basename, relpath|
geometry = config.geometry_alias[geometry] || geometry
file = begin
cachekey = File.join(request_hostname(env), relpath)
Attache.cache.fetch(cachekey) do
Expand Down
7 changes: 3 additions & 4 deletions lib/attache/vhost.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class Attache::VHost
:secret_key,
:bucket,
:storage,
:geometry_alias,
:download_headers,
:headers_with_cors,
:env
Expand All @@ -18,9 +17,9 @@ def initialize(hash)
self.bucket = env['FOG_CONFIG'].fetch('bucket')
self.storage = Fog::Storage.new(env['FOG_CONFIG'].except('bucket').symbolize_keys)
end
self.geometry_alias = env.fetch('GEOMETRY_ALIAS') { {} }
# e.g. GEOMETRY_ALIAS='{ "small": "64x64#", "large": "128x128x#" }'
self.download_headers = env.fetch('DOWNLOAD_HEADERS') { {} }
self.download_headers = {
"Cache-Control" => "public, max-age=31536000"
}.merge(env['DOWNLOAD_HEADERS'] || {})
self.headers_with_cors = {
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Methods' => 'POST, PUT',
Expand Down

0 comments on commit 199ced9

Please sign in to comment.