hobby-rpc 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hobby/rpc.rb +22 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 448a25904b66f7dcc5aa8dcdd8cd9f9c93a49b2b92cc1f6e0b10876e3ff226f0
|
4
|
+
data.tar.gz: c547bfeac7df6e8b9385e0fa22935c0e19363e09e2c2716da93cbd9683d13cd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6f5a67aa5da6f11076c89f612c75632cd5545d264e6671f84cc2f2f6851c27d62e8d5b1431d07e0ad070bc0ca42969ea2a464deabeb0f78cc457d74415a019a
|
7
|
+
data.tar.gz: e39d939760b011b2fce2069abb3c0e712dd3186b1fcbe5ce057633ecb40fcb6d378162dbc34c18647015e77970908909bbaa4f342693eb330d14f13bdae425e4
|
data/lib/hobby/rpc.rb
CHANGED
@@ -1,23 +1,34 @@
|
|
1
1
|
module Hobby
|
2
2
|
class RPC
|
3
3
|
class CORS
|
4
|
-
def initialize app
|
4
|
+
def initialize app, origins: nil
|
5
5
|
@app = app
|
6
|
+
@origins = origins
|
6
7
|
end
|
7
8
|
|
8
9
|
def call env
|
10
|
+
origin = '*'
|
11
|
+
|
12
|
+
if @origins
|
13
|
+
if @origins.include? env['HTTP_ORIGIN']
|
14
|
+
origin = env['HTTP_ORIGIN']
|
15
|
+
else
|
16
|
+
return [400, {}, '400']
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
9
20
|
case env['REQUEST_METHOD']
|
10
21
|
when 'OPTIONS'
|
11
22
|
response = Rack::Response.new
|
12
23
|
|
13
|
-
response.add_header 'Access-Control-Allow-Origin',
|
24
|
+
response.add_header 'Access-Control-Allow-Origin', origin
|
14
25
|
response.add_header 'Access-Control-Allow-Methods', 'POST, OPTIONS'
|
15
26
|
response.add_header 'Access-Control-Allow-Headers', 'Authorization, Content-Type'
|
16
27
|
response.add_header 'Access-Control-Max-Age', '86400'
|
17
28
|
|
18
29
|
response.to_a
|
19
30
|
else
|
20
|
-
status, headers, body = @app.call
|
31
|
+
status, headers, body = @app.call env
|
21
32
|
headers['Access-Control-Allow-Origin'] = '*'
|
22
33
|
[status, headers, body]
|
23
34
|
end
|
@@ -54,8 +65,6 @@ module Hobby
|
|
54
65
|
include Auth[User]
|
55
66
|
include JSON::Keys
|
56
67
|
|
57
|
-
use CORS
|
58
|
-
|
59
68
|
key :fn, String
|
60
69
|
optional {
|
61
70
|
key :in
|
@@ -75,5 +84,13 @@ module Hobby
|
|
75
84
|
response.status = 400
|
76
85
|
end
|
77
86
|
}
|
87
|
+
|
88
|
+
def initialize hash = {}
|
89
|
+
if cors_origins = hash[:cors_origins]
|
90
|
+
use CORS, origins: cors_origins
|
91
|
+
else
|
92
|
+
use CORS
|
93
|
+
end
|
94
|
+
end
|
78
95
|
end
|
79
96
|
end
|