Sha256: 07a234f224f1484821dee7a0dede64a7fc972ff70a468c0550bbb9787554e874
Contents?: true
Size: 1.11 KB
Versions: 20
Compression:
Stored size: 1.11 KB
Contents
# encoding: utf-8 module Hyperdrive module Middleware class CORS def initialize(app, options = {}) @app = app @options = options end def call(env) status, headers, body = @app.call(env) allowed_methods = '*' unless env['hyperdrive.resource'].nil? allowed_methods = env['hyperdrive.resource'].allowed_methods end cors = cors_headers(allowed_methods) headers.merge!(cors) [status, headers, body] end private def cors_headers(allowed_methods = '*') { 'Access-Control-Allow-Origin' => Array(@options[:origins]).join(", "), 'Access-Control-Allow-Methods' => Array(allowed_methods).join(", "), 'Access-Control-Allow-Headers' => Array(@options[:allow_headers]).join(", "), 'Access-Control-Allow-Credentials' => (@options[:credentials] || false).to_s, 'Access-Control-Max-Age' => @options[:max_age].to_i.to_s, 'Access-Control-Expose-Headers' => Array(@options[:expose_headers]).join(", ") } end end end end
Version data entries
20 entries across 20 versions & 1 rubygems