|
1 | 1 | defmodule Dispatcher do |
2 | 2 | use Matcher |
3 | 3 |
|
4 | | - define_accept_types( |
5 | | - text: ["text/*"], |
6 | | - html: ["text/html", "application/xhtml+html"], |
7 | | - json: ["application/json", "application/vnd.api+json"] |
8 | | - ) |
9 | | - |
10 | | - # get "/*_rest", %{ accept: %{ html: true } } do |
11 | | - # Proxy.forward conn, [], "http://static/ember-app/index.html" |
12 | | - # end |
| 4 | + define_accept_types [ |
| 5 | + html: [ "text/html", "application/xhtml+html" ], |
| 6 | + json: [ "application/json", "application/vnd.api+json" ], |
| 7 | + ] |
| 8 | + |
| 9 | + @any %{} |
| 10 | + @json %{ accept: %{ json: true } } |
| 11 | + @html %{ accept: %{ html: true } } |
13 | 12 |
|
14 | | - # get "/assets/*rest", %{} do |
15 | | - # Proxy.forward conn, rest, "http://static/assets/" |
| 13 | + # In order to forward the 'themes' resource to the |
| 14 | + # resource service, use the following forward rule. |
| 15 | + # |
| 16 | + # docker-compose stop; docker-compose rm; docker-compose up |
| 17 | + # after altering this file. |
| 18 | + # |
| 19 | + # match "/themes/*path", @json do |
| 20 | + # Proxy.forward conn, path, "http://resource/themes/" |
16 | 21 | # end |
17 | 22 |
|
18 | | - post "/hello/erika", %{} do |
19 | | - Plug.Conn.send_resp(conn, 401, "FORBIDDEN") |
| 23 | + match "/songs/*path" do |
| 24 | + Proxy.forward conn, path, "http://resource/songs/" |
| 25 | + end |
| 26 | + |
| 27 | + |
| 28 | + match "/bands/*path" do |
| 29 | + Proxy.forward conn, path, "http://resource/bands/" |
20 | 30 | end |
21 | 31 |
|
22 | | - # 200 microservice dispatching |
| 32 | + match "/sessions/*path" do |
| 33 | + Proxy.forward conn, path, "http://login/sessions/" |
| 34 | + end |
| 35 | + |
| 36 | + match "/accounts/*path" do |
| 37 | + Proxy.forward conn, path, "http://registration/accounts/" |
| 38 | + end |
23 | 39 |
|
24 | | - match "/hello/erika", %{accept: %{json: true}} do |
25 | | - Plug.Conn.send_resp(conn, 200, "{ \"message\": \"Hello Erika\" }\n") |
| 40 | + match "/games/*path" do |
| 41 | + Proxy.forward conn, path, "http://resource/games/" |
26 | 42 | end |
27 | 43 |
|
28 | | - match "/hello/erika", %{accept: %{html: true}} do |
29 | | - Plug.Conn.send_resp( |
30 | | - conn, |
31 | | - 200, |
32 | | - "<html><head><title>Hello</title></head><body>Hello Erika</body></html>" |
33 | | - ) |
| 44 | + match "/moves/*path" do |
| 45 | + Proxy.forward conn, path, "http://resource/moves/" |
34 | 46 | end |
35 | 47 |
|
36 | | - # 404 routes |
37 | 48 |
|
38 | | - match "/hello/aad/*_rest", %{accept: %{json: true}} do |
39 | | - Plug.Conn.send_resp(conn, 200, "{ \"message\": \"Hello Aad\" }") |
| 49 | + match "/mine/*path" do |
| 50 | + Proxy.forward conn, path, "http://myMicroservice/" |
40 | 51 | end |
41 | 52 |
|
42 | | - # Websocket example route |
43 | | - # This forwards to /ws?target=<...> |
44 | | - # Then forwards websocket from /ws?target=<...> to ws://localhost:7999 |
| 53 | + match "/websocket/*path" do |
| 54 | + ws(conn, "ws://myMicroservice:8080") |
| 55 | + end |
45 | 56 |
|
46 | | - match "/ws2" do |
47 | | - ws(conn, "ws://localhost:7999") |
| 57 | + match "/echo/*path" do |
| 58 | + ws(conn, "ws://myMicroservice:8081") |
48 | 59 | end |
49 | 60 |
|
| 61 | + match "/sparql/*path" do |
| 62 | + Proxy.forward conn, path, "http://db:8890/sparql" |
| 63 | + end |
50 | 64 |
|
51 | | - match "__", %{last_call: true} do |
52 | | - send_resp(conn, 404, "Route not found. See config/dispatcher.ex") |
| 65 | + match "_", %{ last_call: true } do |
| 66 | + send_resp( conn, 404, "Route not found. See config/dispatcher.ex" ) |
53 | 67 | end |
54 | 68 | end |
0 commit comments