-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move cowboy ws proxy to seperate git repo
- Loading branch information
Showing
10 changed files
with
69 additions
and
171 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,68 @@ | ||
defmodule Dispatcher do | ||
use Matcher | ||
|
||
define_accept_types( | ||
text: ["text/*"], | ||
html: ["text/html", "application/xhtml+html"], | ||
json: ["application/json", "application/vnd.api+json"] | ||
) | ||
|
||
# get "/*_rest", %{ accept: %{ html: true } } do | ||
# Proxy.forward conn, [], "http://static/ember-app/index.html" | ||
# end | ||
define_accept_types [ | ||
html: [ "text/html", "application/xhtml+html" ], | ||
json: [ "application/json", "application/vnd.api+json" ], | ||
] | ||
|
||
@any %{} | ||
@json %{ accept: %{ json: true } } | ||
@html %{ accept: %{ html: true } } | ||
|
||
# get "/assets/*rest", %{} do | ||
# Proxy.forward conn, rest, "http://static/assets/" | ||
# In order to forward the 'themes' resource to the | ||
# resource service, use the following forward rule. | ||
# | ||
# docker-compose stop; docker-compose rm; docker-compose up | ||
# after altering this file. | ||
# | ||
# match "/themes/*path", @json do | ||
# Proxy.forward conn, path, "http://resource/themes/" | ||
# end | ||
|
||
post "/hello/erika", %{} do | ||
Plug.Conn.send_resp(conn, 401, "FORBIDDEN") | ||
match "/songs/*path" do | ||
Proxy.forward conn, path, "http://resource/songs/" | ||
end | ||
|
||
|
||
match "/bands/*path" do | ||
Proxy.forward conn, path, "http://resource/bands/" | ||
end | ||
|
||
# 200 microservice dispatching | ||
match "/sessions/*path" do | ||
Proxy.forward conn, path, "http://login/sessions/" | ||
end | ||
|
||
match "/accounts/*path" do | ||
Proxy.forward conn, path, "http://registration/accounts/" | ||
end | ||
|
||
match "/hello/erika", %{accept: %{json: true}} do | ||
Plug.Conn.send_resp(conn, 200, "{ \"message\": \"Hello Erika\" }\n") | ||
match "/games/*path" do | ||
Proxy.forward conn, path, "http://resource/games/" | ||
end | ||
|
||
match "/hello/erika", %{accept: %{html: true}} do | ||
Plug.Conn.send_resp( | ||
conn, | ||
200, | ||
"<html><head><title>Hello</title></head><body>Hello Erika</body></html>" | ||
) | ||
match "/moves/*path" do | ||
Proxy.forward conn, path, "http://resource/moves/" | ||
end | ||
|
||
# 404 routes | ||
|
||
match "/hello/aad/*_rest", %{accept: %{json: true}} do | ||
Plug.Conn.send_resp(conn, 200, "{ \"message\": \"Hello Aad\" }") | ||
match "/mine/*path" do | ||
Proxy.forward conn, path, "http://myMicroservice/" | ||
end | ||
|
||
# Websocket example route | ||
# This forwards to /ws?target=<...> | ||
# Then forwards websocket from /ws?target=<...> to ws://localhost:7999 | ||
match "/websocket/*path" do | ||
ws(conn, "ws://myMicroservice:8080") | ||
end | ||
|
||
match "/ws2" do | ||
ws(conn, "ws://localhost:7999") | ||
match "/echo/*path" do | ||
ws(conn, "ws://myMicroservice:8081") | ||
end | ||
|
||
match "/sparql/*path" do | ||
Proxy.forward conn, path, "http://db:8890/sparql" | ||
end | ||
|
||
match "__", %{last_call: true} do | ||
send_resp(conn, 404, "Route not found. See config/dispatcher.ex") | ||
match "_", %{ last_call: true } do | ||
send_resp( conn, 404, "Route not found. See config/dispatcher.ex" ) | ||
end | ||
end |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
alias Dispatcher.Log | ||
|
||
defmodule PlugRouterDispatcher do | ||
use Plug.Router | ||
|
||
|
This file was deleted.
Oops, something went wrong.
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
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