2019-09-02 14:29:19 +03:00
|
|
|
defmodule PlausibleWeb.Router do
|
|
|
|
use PlausibleWeb, :router
|
|
|
|
use Plug.ErrorHandler
|
|
|
|
use Sentry.Plug
|
|
|
|
@two_weeks_in_seconds 60 * 60 * 24 * 14
|
|
|
|
|
|
|
|
pipeline :browser do
|
|
|
|
plug :accepts, ["html"]
|
2020-08-11 11:04:26 +03:00
|
|
|
plug PlausibleWeb.Firewall
|
2019-09-02 14:29:19 +03:00
|
|
|
plug :fetch_session
|
|
|
|
plug :fetch_flash
|
|
|
|
plug :put_secure_browser_headers
|
|
|
|
plug PlausibleWeb.SessionTimeoutPlug, timeout_after_seconds: @two_weeks_in_seconds
|
|
|
|
plug PlausibleWeb.AuthPlug
|
|
|
|
plug PlausibleWeb.LastSeenPlug
|
|
|
|
end
|
|
|
|
|
2020-04-14 14:04:35 +03:00
|
|
|
pipeline :csrf do
|
|
|
|
plug :protect_from_forgery
|
|
|
|
end
|
|
|
|
|
2019-09-02 14:29:19 +03:00
|
|
|
pipeline :api do
|
2019-12-03 12:42:17 +03:00
|
|
|
plug :accepts, ["json"]
|
2020-08-11 11:04:26 +03:00
|
|
|
plug PlausibleWeb.Firewall
|
2019-09-02 14:29:19 +03:00
|
|
|
plug :fetch_session
|
|
|
|
plug PlausibleWeb.AuthPlug
|
|
|
|
end
|
|
|
|
|
2019-11-19 07:30:42 +03:00
|
|
|
pipeline :stats_api do
|
|
|
|
plug :accepts, ["json"]
|
2020-08-11 11:04:26 +03:00
|
|
|
plug PlausibleWeb.Firewall
|
2019-11-19 07:30:42 +03:00
|
|
|
plug :fetch_session
|
|
|
|
end
|
|
|
|
|
2020-05-26 16:09:34 +03:00
|
|
|
if Application.get_env(:plausible, :environment) == "dev" do
|
2019-09-02 14:29:19 +03:00
|
|
|
forward "/sent-emails", Bamboo.SentEmailViewerPlug
|
|
|
|
end
|
|
|
|
|
2020-06-11 09:30:00 +03:00
|
|
|
get "/js/plausible.js", PlausibleWeb.TrackerController, :plausible
|
2020-08-25 10:56:36 +03:00
|
|
|
get "/js/plausible.hash.js", PlausibleWeb.TrackerController, :plausible_hash
|
2020-06-11 09:30:00 +03:00
|
|
|
get "/js/analytics.js", PlausibleWeb.TrackerController, :plausible
|
|
|
|
get "/js/p.js", PlausibleWeb.TrackerController, :p
|
|
|
|
|
2019-11-19 07:30:42 +03:00
|
|
|
scope "/api/stats", PlausibleWeb.Api do
|
|
|
|
pipe_through :stats_api
|
|
|
|
|
|
|
|
get "/:domain/current-visitors", StatsController, :current_visitors
|
|
|
|
get "/:domain/main-graph", StatsController, :main_graph
|
|
|
|
get "/:domain/referrers", StatsController, :referrers
|
2020-01-16 16:40:06 +03:00
|
|
|
get "/:domain/goal/referrers", StatsController, :referrers_for_goal
|
2019-11-19 07:30:42 +03:00
|
|
|
get "/:domain/referrers/:referrer", StatsController, :referrer_drilldown
|
2020-01-16 16:40:06 +03:00
|
|
|
get "/:domain/goal/referrers/:referrer", StatsController, :referrer_drilldown_for_goal
|
2019-11-19 07:30:42 +03:00
|
|
|
get "/:domain/pages", StatsController, :pages
|
2020-07-30 11:18:28 +03:00
|
|
|
get "/:domain/entry-pages", StatsController, :entry_pages
|
2019-11-19 07:30:42 +03:00
|
|
|
get "/:domain/countries", StatsController, :countries
|
|
|
|
get "/:domain/browsers", StatsController, :browsers
|
|
|
|
get "/:domain/operating-systems", StatsController, :operating_systems
|
|
|
|
get "/:domain/screen-sizes", StatsController, :screen_sizes
|
|
|
|
get "/:domain/conversions", StatsController, :conversions
|
|
|
|
end
|
|
|
|
|
2019-09-02 14:29:19 +03:00
|
|
|
scope "/api", PlausibleWeb do
|
|
|
|
pipe_through :api
|
|
|
|
|
2019-10-31 06:49:46 +03:00
|
|
|
post "/event", Api.ExternalController, :event
|
2019-09-02 14:29:19 +03:00
|
|
|
get "/error", Api.ExternalController, :error
|
2020-07-20 10:34:35 +03:00
|
|
|
get "/health", Api.ExternalController, :health
|
2019-09-02 14:29:19 +03:00
|
|
|
|
|
|
|
post "/paddle/webhook", Api.PaddleController, :webhook
|
|
|
|
|
|
|
|
get "/:domain/status", Api.InternalController, :domain_status
|
2020-08-13 13:45:18 +03:00
|
|
|
get "/sites", Api.InternalController, :sites
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
scope "/", PlausibleWeb do
|
|
|
|
pipe_through :browser
|
|
|
|
|
|
|
|
get "/register", AuthController, :register_form
|
|
|
|
post "/register", AuthController, :register
|
|
|
|
get "/claim-activation", AuthController, :claim_activation_link
|
|
|
|
get "/login", AuthController, :login_form
|
|
|
|
post "/login", AuthController, :login
|
|
|
|
get "/password/request-reset", AuthController, :password_reset_request_form
|
|
|
|
post "/password/request-reset", AuthController, :password_reset_request
|
|
|
|
get "/password/reset", AuthController, :password_reset_form
|
|
|
|
post "/password/reset", AuthController, :password_reset
|
2020-04-14 14:04:35 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
scope "/", PlausibleWeb do
|
|
|
|
pipe_through [:browser, :csrf]
|
|
|
|
|
2019-09-02 14:29:19 +03:00
|
|
|
get "/password", AuthController, :password_form
|
|
|
|
post "/password", AuthController, :set_password
|
|
|
|
post "/logout", AuthController, :logout
|
|
|
|
get "/settings", AuthController, :user_settings
|
|
|
|
put "/settings", AuthController, :save_settings
|
|
|
|
delete "/me", AuthController, :delete_me
|
|
|
|
|
|
|
|
get "/auth/google/callback", AuthController, :google_auth_callback
|
|
|
|
|
|
|
|
get "/", PageController, :index
|
|
|
|
|
|
|
|
get "/billing/change-plan", BillingController, :change_plan_form
|
2020-04-21 14:11:38 +03:00
|
|
|
get "/billing/change-plan/preview/:plan_id", BillingController, :change_plan_preview
|
|
|
|
post "/billing/change-plan/:new_plan_id", BillingController, :change_plan
|
2019-09-02 14:29:19 +03:00
|
|
|
get "/billing/upgrade", BillingController, :upgrade
|
2020-08-18 12:48:01 +03:00
|
|
|
get "/billing/upgrade-success", BillingController, :upgrade_success
|
2019-09-02 14:29:19 +03:00
|
|
|
|
2020-03-31 16:16:21 +03:00
|
|
|
get "/sites", SiteController, :index
|
2019-09-02 14:29:19 +03:00
|
|
|
get "/sites/new", SiteController, :new
|
|
|
|
post "/sites", SiteController, :create_site
|
|
|
|
post "/sites/:website/make-public", SiteController, :make_public
|
|
|
|
post "/sites/:website/make-private", SiteController, :make_private
|
2019-09-09 14:37:57 +03:00
|
|
|
post "/sites/:website/weekly-report/enable", SiteController, :enable_weekly_report
|
|
|
|
post "/sites/:website/weekly-report/disable", SiteController, :disable_weekly_report
|
2020-01-22 12:16:53 +03:00
|
|
|
post "/sites/:website/weekly-report/recipients", SiteController, :add_weekly_report_recipient
|
2020-06-08 10:35:13 +03:00
|
|
|
|
|
|
|
delete "/sites/:website/weekly-report/recipients/:recipient",
|
|
|
|
SiteController,
|
|
|
|
:remove_weekly_report_recipient
|
|
|
|
|
2019-09-09 14:37:57 +03:00
|
|
|
post "/sites/:website/monthly-report/enable", SiteController, :enable_monthly_report
|
|
|
|
post "/sites/:website/monthly-report/disable", SiteController, :disable_monthly_report
|
2020-06-08 10:35:13 +03:00
|
|
|
|
|
|
|
post "/sites/:website/monthly-report/recipients",
|
|
|
|
SiteController,
|
|
|
|
:add_monthly_report_recipient
|
|
|
|
|
|
|
|
delete "/sites/:website/monthly-report/recipients/:recipient",
|
|
|
|
SiteController,
|
|
|
|
:remove_monthly_report_recipient
|
2020-01-22 12:16:53 +03:00
|
|
|
|
2020-01-29 12:29:11 +03:00
|
|
|
get "/sites/:website/shared-links/new", SiteController, :new_shared_link
|
|
|
|
post "/sites/:website/shared-links", SiteController, :create_shared_link
|
|
|
|
delete "/sites/:website/shared-links/:slug", SiteController, :delete_shared_link
|
|
|
|
|
2020-02-26 11:54:21 +03:00
|
|
|
get "/sites/:website/custom-domains/new", SiteController, :new_custom_domain
|
|
|
|
get "/sites/:website/custom-domains/dns-setup", SiteController, :custom_domain_dns_setup
|
|
|
|
get "/sites/:website/custom-domains/snippet", SiteController, :custom_domain_snippet
|
|
|
|
post "/sites/:website/custom-domains", SiteController, :add_custom_domain
|
2020-06-30 11:00:19 +03:00
|
|
|
delete "/sites/:website/custom-domains/:id", SiteController, :delete_custom_domain
|
2020-02-26 11:54:21 +03:00
|
|
|
|
2020-01-22 12:16:53 +03:00
|
|
|
get "/sites/:website/weekly-report/unsubscribe", UnsubscribeController, :weekly_report
|
|
|
|
get "/sites/:website/monthly-report/unsubscribe", UnsubscribeController, :monthly_report
|
|
|
|
|
2019-09-02 14:29:19 +03:00
|
|
|
get "/:website/snippet", SiteController, :add_snippet
|
|
|
|
get "/:website/settings", SiteController, :settings
|
2019-10-31 08:39:51 +03:00
|
|
|
get "/:website/goals", SiteController, :goals
|
|
|
|
get "/:website/goals/new", SiteController, :new_goal
|
|
|
|
post "/:website/goals", SiteController, :create_goal
|
2019-10-31 09:20:45 +03:00
|
|
|
delete "/:website/goals/:id", SiteController, :delete_goal
|
2019-09-02 14:29:19 +03:00
|
|
|
put "/:website/settings", SiteController, :update_settings
|
2019-10-10 07:12:15 +03:00
|
|
|
put "/:website/settings/google", SiteController, :update_google_auth
|
2020-06-30 11:11:47 +03:00
|
|
|
delete "/:website/settings/google", SiteController, :delete_google_auth
|
2019-09-02 14:29:19 +03:00
|
|
|
delete "/:website", SiteController, :delete_site
|
2020-07-16 13:07:45 +03:00
|
|
|
delete "/:website/stats", SiteController, :reset_stats
|
2019-09-02 14:29:19 +03:00
|
|
|
|
2020-01-29 12:29:11 +03:00
|
|
|
get "/share/:slug", StatsController, :shared_link
|
|
|
|
post "/share/:slug/authenticate", StatsController, :authenticate_shared_link
|
2020-04-14 14:04:35 +03:00
|
|
|
get "/:domain/visitors.csv", StatsController, :csv_export
|
|
|
|
get "/:domain/*path", StatsController, :stats
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|
|
|
|
end
|