hobby-cors 0.0.0 → 0.1.0
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 +4 -4
- data/lib/hobby/cors.rb +30 -5
- metadata +14 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5e015f024ff9151f35aa4cf941f75ce9480c83984a0617dd12d56c991bdd8c7
|
4
|
+
data.tar.gz: 7e693bc6293c8388293cf400b8a8b42574be5aecd1e9f8c6b34b6f4110ec12c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b73e2f5d700a708de2da36f5a7d09014fe944147d33742008b09542cae239b993cbf9578acd5106d8d42561acb2f7a3d6d114fa0807e344f016d51bb788bb4a
|
7
|
+
data.tar.gz: 5078de1fd7f111cc68c5bbb680396b63bfa1696efb33533c044038e8081a7d4327d5df349b4f761edd4bc7d71a1c5688cd42ccae28542464a9dc37a8c629b06c
|
data/lib/hobby/cors.rb
CHANGED
@@ -1,13 +1,38 @@
|
|
1
|
+
require 'rack'
|
2
|
+
|
1
3
|
module Hobby
|
2
|
-
class
|
3
|
-
def initialize app
|
4
|
+
class CORS
|
5
|
+
def initialize app, origins: nil
|
4
6
|
@app = app
|
7
|
+
@origins = origins
|
5
8
|
end
|
6
9
|
|
7
10
|
def call env
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
origin = '*'
|
12
|
+
|
13
|
+
if @origins
|
14
|
+
if @origins.include? env['HTTP_ORIGIN']
|
15
|
+
origin = env['HTTP_ORIGIN']
|
16
|
+
else
|
17
|
+
return [400, {}, []]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
case env['REQUEST_METHOD']
|
22
|
+
when 'OPTIONS'
|
23
|
+
response = Rack::Response.new
|
24
|
+
|
25
|
+
response.add_header 'Access-Control-Allow-Origin', origin
|
26
|
+
response.add_header 'Access-Control-Allow-Methods', 'POST, OPTIONS'
|
27
|
+
response.add_header 'Access-Control-Allow-Headers', 'Authorization, Content-Type'
|
28
|
+
response.add_header 'Access-Control-Max-Age', '86400'
|
29
|
+
|
30
|
+
response.to_a
|
31
|
+
else
|
32
|
+
status, headers, body = @app.call env
|
33
|
+
headers['Access-Control-Allow-Origin'] = origin
|
34
|
+
[status, headers, body]
|
35
|
+
end
|
11
36
|
end
|
12
37
|
end
|
13
38
|
end
|
metadata
CHANGED
@@ -1,38 +1,40 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hobby-cors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Anatoly
|
7
|
+
- Anatoly Chernov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2'
|
27
27
|
description:
|
28
|
-
email:
|
28
|
+
email:
|
29
|
+
- chertoly@gmail.com
|
29
30
|
executables: []
|
30
31
|
extensions: []
|
31
32
|
extra_rdoc_files: []
|
32
33
|
files:
|
33
34
|
- lib/hobby/cors.rb
|
34
|
-
homepage:
|
35
|
-
licenses:
|
35
|
+
homepage: https://github.com/ch1c0t/hobby-cors
|
36
|
+
licenses:
|
37
|
+
- ISC
|
36
38
|
metadata: {}
|
37
39
|
post_install_message:
|
38
40
|
rdoc_options: []
|
@@ -49,9 +51,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
51
|
- !ruby/object:Gem::Version
|
50
52
|
version: '0'
|
51
53
|
requirements: []
|
52
|
-
|
53
|
-
rubygems_version: 2.7.6
|
54
|
+
rubygems_version: 3.1.6
|
54
55
|
signing_key:
|
55
56
|
specification_version: 4
|
56
|
-
summary: A Rack CORS
|
57
|
+
summary: A Rack middleware for CORS, with permissive defaults.
|
57
58
|
test_files: []
|