grape-cors 0.9.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 +7 -0
- data/.gitignore +34 -0
- data/Gemfile +2 -0
- data/LICENSE +21 -0
- data/README.md +50 -0
- data/Rakefile +1 -0
- data/VERSION +1 -0
- data/grape-cors.gemspec +23 -0
- data/lib/grape-cors.rb +73 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f4898cbab42330fac9c5d80657c4d580ba2a89fb
|
4
|
+
data.tar.gz: c5ff8422c68ac3c098b5138b091ba95fe90168fa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4f109120eb769eb5bbe39d6f08d666f4fdc27729229411b706082d68154a39ccb10b2f9081c05684126b4a0955cdaabc7c158cae9fdc943294e491f546d5a9f7
|
7
|
+
data.tar.gz: 85879f46952a144aa25721978871ea11fffa3ff324670e2fb8b984d69053b50b8e3d8eaac396ad15feac9f0726c5359b2c4f0a94453cf260fe9e1a323bf92967
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Adam Luzsi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
grape-cors
|
2
|
+
==========
|
3
|
+
|
4
|
+
Ruby Grape Api extension with Cross-origin resource sharing
|
5
|
+
|
6
|
+
### Example:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
|
10
|
+
class API < Grape::API
|
11
|
+
|
12
|
+
get :info do
|
13
|
+
#> some logic here
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
Grape::CORS.apply!
|
19
|
+
#> and ready to use!
|
20
|
+
|
21
|
+
```
|
22
|
+
|
23
|
+
In case if you need to use the 'options' call, you should use by hand the following method:
|
24
|
+
* init_cors_headers!
|
25
|
+
because the apply method will not override the options enpoints (safety reasons)
|
26
|
+
And otherwise, that option call will lack the required headers
|
27
|
+
|
28
|
+
if you want change any of the cors object, you can do so in the following way:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
|
32
|
+
#> Defaults
|
33
|
+
Grape::CORS::Config.headers #> [ 'Content-Type' ]
|
34
|
+
Grape::CORS::Config.origin #> [ '*' ]
|
35
|
+
Grape::CORS::Config.methods #> [ 'HEAD', 'OPTIONS', 'GET', 'POST', 'PUT', 'DELETE' ]
|
36
|
+
|
37
|
+
Grape::CORS::Config.acah #> 'Access-Control-Allow-Headers'
|
38
|
+
Grape::CORS::Config.acao #> 'Access-Control-Allow-Origin'
|
39
|
+
Grape::CORS::Config.acam #> 'Access-Control-Allow-Methods'
|
40
|
+
|
41
|
+
```
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
|
45
|
+
Grape::CORS::Config.origin.clear
|
46
|
+
Grape::CORS::Config.origin.push(some_origin_site)
|
47
|
+
|
48
|
+
```
|
49
|
+
|
50
|
+
Happy coding! :)
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join"bundler","gem_tasks"
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.9.0
|
data/grape-cors.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
|
5
|
+
spec.name = "grape-cors"
|
6
|
+
spec.version = File.read(File.join(File.dirname(__FILE__),"VERSION")).split("\n")[0].chomp.gsub(' ','')
|
7
|
+
spec.authors = ["Adam Luzsi"]
|
8
|
+
spec.email = ["adamluzsi@gmail.com"]
|
9
|
+
|
10
|
+
spec.description = %q{ Super easy way to extend Grape with CORS! Just call Grape::CORS.apply after the api classes and you ready to go! }
|
11
|
+
spec.summary = %q{ Super easy way to extend Grape with CORS! }
|
12
|
+
|
13
|
+
spec.homepage = "https://github.com/adamluzsi/#{__FILE__.split(File::Separator).last.split('.').first}"
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler"
|
20
|
+
spec.add_development_dependency "rake"
|
21
|
+
spec.add_dependency "grape"
|
22
|
+
|
23
|
+
end
|
data/lib/grape-cors.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'grape'
|
2
|
+
module Grape
|
3
|
+
module CORS
|
4
|
+
|
5
|
+
module EndPointHelpers
|
6
|
+
def init_cors_headers!
|
7
|
+
Grape::CORS::Config.object.each_pair do |header_key,header_value|
|
8
|
+
header header_key, header_value.join(', ')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
Grape::Endpoint.__send__ :include, EndPointHelpers
|
14
|
+
|
15
|
+
module Config
|
16
|
+
@headers ||= ['Content-Type']
|
17
|
+
@origin ||= ['*']
|
18
|
+
@methods ||= %W[ HEAD OPTIONS GET POST PUT DELETE ]
|
19
|
+
@acah ||= 'Access-Control-Allow-Headers'
|
20
|
+
@acao ||= 'Access-Control-Allow-Origin'
|
21
|
+
@acam ||= 'Access-Control-Allow-Methods'
|
22
|
+
class << self
|
23
|
+
|
24
|
+
attr_reader :headers,:origin,:methods,
|
25
|
+
:acah,:acao,:acam
|
26
|
+
|
27
|
+
def object
|
28
|
+
{
|
29
|
+
Config.acah => Config.headers,
|
30
|
+
Config.acao => Config.origin,
|
31
|
+
Config.acam => Config.methods
|
32
|
+
}
|
33
|
+
end;alias obj object
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class << self
|
39
|
+
|
40
|
+
def apply
|
41
|
+
|
42
|
+
ObjectSpace.each_object(Class).select { |klass| klass < Grape::API rescue false }.each do |api_class|
|
43
|
+
api_class.class_eval do
|
44
|
+
|
45
|
+
before do
|
46
|
+
init_cors_headers!
|
47
|
+
end
|
48
|
+
|
49
|
+
self.routes.map { |route|
|
50
|
+
|
51
|
+
#> get all non options call
|
52
|
+
unless route.route_method == "OPTIONS"
|
53
|
+
route.route_path.to_s.sub(/\(\.:format\)$/,'')
|
54
|
+
end
|
55
|
+
}.compact.uniq.each do |path|
|
56
|
+
|
57
|
+
#> CORS Option calls
|
58
|
+
options path do
|
59
|
+
init_cors_headers!
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
return nil
|
68
|
+
|
69
|
+
end;alias apply! apply
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: grape-cors
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Luzsi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: grape
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: " Super easy way to extend Grape with CORS! Just call Grape::CORS.apply
|
56
|
+
after the api classes and you ready to go! "
|
57
|
+
email:
|
58
|
+
- adamluzsi@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- VERSION
|
69
|
+
- grape-cors.gemspec
|
70
|
+
- lib/grape-cors.rb
|
71
|
+
homepage: https://github.com/adamluzsi/grape-cors
|
72
|
+
licenses: []
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.2.2
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Super easy way to extend Grape with CORS!
|
94
|
+
test_files: []
|
95
|
+
has_rdoc:
|