Last active
December 16, 2015 17:59
-
-
Save cstorey/5474588 to your computer and use it in GitHub Desktop.
Trivial CORS enabled lobster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 require 'rack/cors' | |
2 require 'sinatra' | |
3 | |
4 get '/' do | |
5 "Hello world" | |
6 end | |
7 | |
8 use Rack::Cors do | |
9 allow do | |
10 origins 'localhost:3000', '127.0.0.1:3000', | |
11 /http:\/\/192\.168\.0\.\d{1,3}(:\d+)?/ | |
12 # regular expressions can be used here | |
13 | |
14 resource '/file/list_all/', :headers => 'x-domain-token' | |
15 resource '/file/at/*', | |
16 :methods => [:get, :post, :put, :delete, :options], | |
17 :headers => 'x-domain-token', | |
18 :expose => ['Some-Custom-Response-Header'] | |
19 # headers to expose | |
20 end | |
21 | |
22 allow do | |
23 origins '*' | |
24 resource '/public/*', :headers => :any, :methods => :get | |
25 end | |
26 end | |
27 | |
28 run Sinatra::Application |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment