Skip to content

Commit

Permalink
add custom origin check
Browse files Browse the repository at this point in the history
  • Loading branch information
aayushmau5 committed Jun 2, 2024
1 parent 0dc104e commit caff5da
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 7 deletions.
6 changes: 1 addition & 5 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ config :accumulator, Accumulator.Mailer, adapter: Resend.Swoosh.Adapter
# before starting your production server.
config :accumulator, AccumulatorWeb.Endpoint,
cache_static_manifest: "priv/static/cache_manifest.json",
check_origin: [
"https://aayushsahu.com",
"https://phoenix-aayushsahu-com.fly.dev",
"https://phoenix.aayushsahu.com/"
]
check_origin: {Accumulator.Origin, :my_check_origin?, []}

# Do not print debug messages in production
config :logger, level: :info
Expand Down
12 changes: 12 additions & 0 deletions lib/accumulator/origin.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
defmodule Accumulator.Origin do
@allowed_hosts ["aayushsahu.com", "phoenix.aayushsahu.com"]

def my_check_origin?(%URI{scheme: scheme, host: host} = _uri) do
case scheme do
"moz-extension" -> true
"chrome-extension" -> true
"https" -> if host in @allowed_hosts, do: true, else: false
_ -> false
end
end
end
3 changes: 1 addition & 2 deletions lib/accumulator_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,5 @@ defmodule AccumulatorWeb.Endpoint do

socket "/extension", AccumulatorWeb.ExtensionSocket,
websocket: true,
longpoll: false,
check_origin: false
longpoll: false
end
Binary file removed priv/static/fonts/OverpassMono-Bold.ttf
Binary file not shown.
Binary file removed priv/static/fonts/OverpassMono-Light.ttf
Binary file not shown.
Binary file removed priv/static/fonts/OverpassMono-Medium.ttf
Binary file not shown.
Binary file removed priv/static/fonts/OverpassMono-Regular.ttf
Binary file not shown.
Binary file removed priv/static/fonts/OverpassMono-SemiBold.ttf
Binary file not shown.

0 comments on commit caff5da

Please sign in to comment.