-
-
Save bernd/407445 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module CouchDBAttachments | |
def attachment(*args) | |
lambda do |env| | |
request = ActionDispatch::Request.new(env) | |
doc = DocWithAttachments.get(request.params[:doc]) | |
serve_attachment(doc, request.params[:path]) | |
end | |
end | |
private | |
# TODO: Add whatever you want | |
def serve_attachment(doc, filename) | |
if doc && attachment = doc["_attachments"][filename] | |
headers = {} | |
headers["Content-Type"] = attachment["content_type"] | |
headers["Content-Disposition"] = "inline; filename=#{filename}" | |
headers["X-Accel-Redirect"] = "/couch/#{doc.database.name}/#{doc["_id"]}/#{filename}" | |
[200, headers, []] | |
else | |
[404, { "Content-Type", "text/html" }, []] | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http { | |
include mime.types; | |
default_type application/octet-stream; | |
upstream couchdb { | |
server 127.0.0.1:5984; | |
} | |
upstream unicorn { | |
server 127.0.0.1:3000; | |
} | |
server { | |
listen 7000; | |
server_name proxy.caprica.local; | |
location / { | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
proxy_redirect off; | |
proxy_pass http://unicorn/; | |
} | |
location /couch/ { | |
internal; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_pass http://couchdb/; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Example::Application.routes.draw do |map| | |
extend CouchDBAttachments | |
match "/assets/:doc/*path", :to => attachment() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment