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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hobby/rpc.rb +22 -5
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34cd6d8707a326830ee359ffd413ca313a4893fbe5545cbb3423171a659f57a6
4
- data.tar.gz: c7e6e3f1202778b76b956d46d087951c0fc5b53ed9779c7b775898825e3b014e
3
+ metadata.gz: 448a25904b66f7dcc5aa8dcdd8cd9f9c93a49b2b92cc1f6e0b10876e3ff226f0
4
+ data.tar.gz: c547bfeac7df6e8b9385e0fa22935c0e19363e09e2c2716da93cbd9683d13cd8
5
5
  SHA512:
6
- metadata.gz: 89ac9149cff9c6c44608cd97ec8a2ac8ab83ce069fc27c65279903f25a9d422edb8def1a973ff9d73f20e9f649d5250f35a595e4255b7d5760eff26dffbe9304
7
- data.tar.gz: ccb6c62344c3dbdc7c25628768eb9e38ec87f236bf0fef59de9fbeddea7372a8f49dd14a6fe39f447f5f78d9176b9d3a81e2985f7f9aff2b61fcb7405b2d5571
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(env).to_a
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hobby-rpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatoly Chernov