upfluence-utils 0.5.5 → 0.5.6
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.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 74c35a15e8d437a42908c4a72f26039143ffb7b2
|
|
4
|
+
data.tar.gz: d0d629dfe83c1790d15d25070cc28fd3911f2d55
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ad20176b39f988ab15f25906c936463de58182974a1b8d8cd435c00586996e6c9648d6a9c60adca9378a53576da2b982c8bd8638b2ac972fa8e41984e6e8ef34
|
|
7
|
+
data.tar.gz: e4ffa03cb0d0e392df2b0f5a09fa0d2bd7db0925a91f17e9759751462811a4b63a08259d9ddcec6a5bf79b43eb46b90a5e21e7e8da3252028e6ea96a8b8739b2
|
|
@@ -47,10 +47,12 @@ module Upfluence
|
|
|
47
47
|
).to_json
|
|
48
48
|
else
|
|
49
49
|
status = 200
|
|
50
|
+
opts = args.first || {}
|
|
51
|
+
|
|
50
52
|
result = if resource.is_a? Enumerable
|
|
51
|
-
ActiveModel::ArraySerializer.new(
|
|
52
|
-
|
|
53
|
-
).to_json
|
|
53
|
+
ActiveModel::ArraySerializer.new(resource, *args).to_json
|
|
54
|
+
elsif opts[:serializer]
|
|
55
|
+
opts[:serializer].new(resource, *args).to_json
|
|
54
56
|
elsif resource.respond_to?(:serialize)
|
|
55
57
|
resource.serialize(*args).to_json
|
|
56
58
|
else
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Upfluence
|
|
2
|
+
module HTTP
|
|
3
|
+
module Middleware
|
|
4
|
+
class CORS
|
|
5
|
+
HEADERS = {
|
|
6
|
+
'Access-Control-Allow-Origin' => '*',
|
|
7
|
+
'Access-Control-Allow-Headers' => 'Authorization, Content-Type, Scope',
|
|
8
|
+
'Access-Control-Allow-Methods' => 'GET, POST, PUT, OPTIONS, DELETE'
|
|
9
|
+
}.freeze
|
|
10
|
+
|
|
11
|
+
def initialize(app, headers = nil)
|
|
12
|
+
@app = app
|
|
13
|
+
@headers = headers || HEADERS
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def call(env)
|
|
17
|
+
status, headers, body = options?(env) ? default_response : @app.call(env)
|
|
18
|
+
[status, merge_headers(headers), body]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def default_response
|
|
24
|
+
[200, {}, ['']]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def options?(env)
|
|
28
|
+
Rack::Request.new(env).options?
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def merge_headers(headers)
|
|
32
|
+
headers.merge(@headers) { |_, x, _| x }
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -13,6 +13,7 @@ require 'upfluence/http/middleware/logger'
|
|
|
13
13
|
require 'upfluence/http/middleware/application_headers'
|
|
14
14
|
require 'upfluence/http/middleware/handle_exception'
|
|
15
15
|
require 'upfluence/http/middleware/prometheus'
|
|
16
|
+
require 'upfluence/http/middleware/cors'
|
|
16
17
|
require 'upfluence/handler/base'
|
|
17
18
|
|
|
18
19
|
module Upfluence
|
|
@@ -47,6 +48,7 @@ module Upfluence
|
|
|
47
48
|
use Rack::Lint if Upfluence.env.development?
|
|
48
49
|
use Rack::TempfileReaper
|
|
49
50
|
use Rack::ETag
|
|
51
|
+
use Middleware::CORS if Upfluence.env.development?
|
|
50
52
|
|
|
51
53
|
map '/healthcheck' do
|
|
52
54
|
run(opts[:healthcheck_endpoint] || Endpoint::Healthcheck.new)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: upfluence-utils
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Upfluence
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-
|
|
11
|
+
date: 2018-06-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -254,6 +254,7 @@ files:
|
|
|
254
254
|
- lib/upfluence/http/endpoint/healthcheck.rb
|
|
255
255
|
- lib/upfluence/http/endpoint/profiler.rb
|
|
256
256
|
- lib/upfluence/http/middleware/application_headers.rb
|
|
257
|
+
- lib/upfluence/http/middleware/cors.rb
|
|
257
258
|
- lib/upfluence/http/middleware/handle_exception.rb
|
|
258
259
|
- lib/upfluence/http/middleware/logger.rb
|
|
259
260
|
- lib/upfluence/http/middleware/prometheus.rb
|