File tree 5 files changed +41
-18
lines changed
5 files changed +41
-18
lines changed Original file line number Diff line number Diff line change @@ -8,9 +8,6 @@ rackup -q -p 8080
8
8
9
9
As you can see from the ` config.ru ` , it will forward all requests according to this table:
10
10
11
- | Route | Target |
12
- | ----------------| -------------------------------|
13
- | /oauth/ | http://auth.host/oauth/ |
14
- | /oauth/token | http://auth.host/oauth/token |
15
- | /api/ | http://api.host/api/ |
16
- | /api/something | http://api.host/api/something |
11
+ | Route | Target |
12
+ | ----------------| ------------------------------------------------|
13
+ | /api/* | http://jsonplaceholder.typicode.com/* |
Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ app = Rack::Builder.new do
4
4
map '/api' do
5
5
run ApiValve ::Proxy . from_hash ( endpoint : 'https://jsonplaceholder.typicode.com' )
6
6
end
7
- map '/oauth ' do
8
- run ApiValve :: Proxy . from_hash ( endpoint : 'http://auth.host/oauth/' )
7
+ map '/health ' do
8
+ run -> ( _env ) { [ 200 , { } , [ '' ] ] }
9
9
end
10
10
end
11
11
Original file line number Diff line number Diff line change @@ -8,10 +8,10 @@ rackup -q -p 8080
8
8
9
9
As you can see from the ` config.ru ` , it will forward all requests according to this table:
10
10
11
- | Method | Route | Target |
12
- | --------| -----------------------| -----------------------|
13
- | GET | /api/* | http://api.host/api/* |
14
- | GET | /api/prefix /* | http://api.host/api /* |
15
- | POST | * | HTTP Error 403 |
16
- | PUT | * | HTTP Error 403 |
17
- | PATCH | * | HTTP Error 403 |
11
+ | Method | Route | Target |
12
+ | --------| -------------------| ---------------------- -----------------------|
13
+ | GET | /api/* | http://jsonplaceholder.typicode.com/* |
14
+ | GET | /api/customers /* | http://jsonplaceholder.typicode.com/users /* |
15
+ | POST | * | HTTP Error 403 |
16
+ | PUT | * | HTTP Error 403 |
17
+ | PATCH | * | HTTP Error 403 |
Original file line number Diff line number Diff line change 1
1
require 'api_valve'
2
+ require 'byebug'
2
3
3
4
app = Rack ::Builder . new do
4
5
use ApiValve ::Middleware ::ErrorHandling
5
6
use ApiValve ::Middleware ::Logging
6
7
7
8
map '/api' do
8
9
run ApiValve ::Proxy . from_hash (
9
- endpoint : 'http://api.host/api/ ' ,
10
+ endpoint : 'http://jsonplaceholder.typicode.com ' ,
10
11
routes : [
11
12
{
12
13
method : 'get' ,
13
- path : %r{^/prefix/(?<final_path>.*)} ,
14
- request : { path : '%{final_path}' }
14
+ path : %r{^/customers/(?<path>.*)} ,
15
+ request : { path : '/users/%{path}' }
16
+ } ,
17
+ {
18
+ method : 'get'
15
19
} ,
16
20
{
17
21
method : 'post' ,
Original file line number Diff line number Diff line change
1
+ RSpec . describe 'Routing example' , type : :feature do
2
+ let ( :app ) { example_app 'routing' }
3
+
4
+ before do
5
+ stub_request ( :get , %r{^http://jsonplaceholder.typicode.com/users} )
6
+ . to_return ( status : 204 , headers : { 'Content-Type' => 'application/json' } )
7
+ end
8
+
9
+ describe "GET '/api/customers/1'" do
10
+ it 'correctly forwards the request' do
11
+ get '/api/customers/1'
12
+ expect ( WebMock ) . to ( have_requested ( :get , 'http://jsonplaceholder.typicode.com/users/1' ) )
13
+ end
14
+ end
15
+
16
+ describe "GET '/api/users/2'" do
17
+ it 'correctly forwards the request' do
18
+ get '/api/users/2'
19
+ expect ( WebMock ) . to ( have_requested ( :get , 'http://jsonplaceholder.typicode.com/users/2' ) )
20
+ end
21
+ end
22
+ end
You can’t perform that action at this time.
0 commit comments