z_sites_dispatcher (zotonic_core v1.0.0-rc.17)
Server for matching the request path to correct site and dispatch rule.
Summary
Functions
Convert process state when code is changed
Collect all dispatch rules for all running sites, normalize and filter them.
Collect all dispatch rules for all sites, normalize and filter them.
Match the host and path to a dispatch rule.
Dispatch a path for a host, return the extracted dispatch information and bindings. Used for matching URLs to dispatch rules and ids.
Dispatch an URL, return the extracted dispatch information and bindings. Used for matching URLs to dispatch rules and ids.
Cowboy middleware, route the new request. Continue with the cowmachine, requests a redirect or return a 400 on an unknown host. The cowmachine_proxy middleware must have been called before this.
Fetch dispatch rules for a specific site.
Retrieve the fallback site.
Fetch the site handling the given hostname (with optional port)
Fetch the site handling the given URL. Scheme is not checked.
Trap unknown calls
Load all dispatch rules, if anything changed then recompile the dispatcher(s)
Handling all non call/cast messages
Initiates the server.
Callback for the dispatch compiler, try to bind a language
Starts the server
This function is called by a gen_server when it is about to terminate. It should be the opposite of Module:init/1 and do any necessary cleaning up. When it returns, the gen_server terminates with Reason. The return value is ignored.
Collect dispatch information from all sites and recompiles the dispatch rules.
Update the host/site mappings
Types
-type binding() :: dispatch_compiler:binding() | {atom(), atom()}.
-type bindings() :: [binding()].
-type dispatch() :: #dispatch_controller{dispatch_rule :: atom(), controller :: atom(), controller_options :: list(), path_tokens :: [binary()], bindings :: bindings(), context :: z:context()} | #dispatch_nomatch{site :: atom(), host :: binary(), path_tokens :: [binary()], bindings :: bindings(), context :: #context{cowreq :: cowboy_req:req() | undefined, cowenv :: cowboy_middleware:env() | undefined, site :: atom(), controller_module :: atom() | undefined, client_id :: binary() | undefined, client_topic :: mqtt_sessions:topic() | undefined, routing_id :: binary() | undefined, acl :: term() | admin | undefined, acl_is_read_only :: boolean(), user_id :: integer() | authenticated | undefined, render_state :: undefined | z_render:render_state(), db :: {atom(), atom()} | undefined, dbc :: pid() | undefined, language :: [atom()], tz :: binary(), props :: map(), depcache :: pid() | atom(), dispatcher :: pid() | atom(), template_server :: pid() | atom(), scomp_server :: pid() | atom(), dropbox_server :: pid() | atom(), pivot_server :: pid() | atom(), module_indexer :: pid() | atom(), translation_table :: atom()} | undefined} | redirect() | redirect_protocol() | stop_request().
-type dispatch_rule() :: dispatch_compiler:dispatch_rule() | dispatch_rsc_rule().
-type site_dispatch_list() :: #site_dispatch_list{site :: atom(), hostname :: z_sites_dispatcher:hostname(), smtphost :: z_sites_dispatcher:hostname() | undefined, hostalias :: [z_sites_dispatcher:hostname()], redirect :: boolean(), dispatch_list :: [z_sites_dispatcher:dispatch_rule()], page_paths :: #{atom() | binary() => z_sites_dispatcher:dispatch_rsc_rule()}}.
-type stop_request() :: #stop_request{status :: pos_integer()}.
-type trace() :: #{path := binary() | [binary()] | undefined, step := trace_step(), args := proplists:proplist()}.
-type trace_step() ::
undefined | match | try_match | dispatch_rewrite | forced_protocol_switch | notify_dispatch |
rewrite_id | rewrite_match | rewrite_nomatch.
Functions
Convert process state when code is changed
Collect all dispatch rules for all running sites, normalize and filter them.
Collect all dispatch rules for all sites, normalize and filter them.
-spec dispatch(cowboy_req:req(), cowboy_middleware:env()) -> dispatch().
Match the host and path to a dispatch rule.
-spec dispatch_path(binary() | string(), z:context()) -> {ok, map()} | {error, non_neg_integer() | invalid}.
Dispatch a path for a host, return the extracted dispatch information and bindings. Used for matching URLs to dispatch rules and ids.
-spec dispatch_url(binary() | string()) -> {ok, map()} | {error, non_neg_integer() | invalid}.
Dispatch an URL, return the extracted dispatch information and bindings. Used for matching URLs to dispatch rules and ids.
-spec execute(Req, Env) -> Result when Req :: cowboy_req:req(), Env :: cowboy_middleware:env(), Result :: {ok, Req1, Env1} | {stop, Req1}, Req1 :: cowboy_req:req(), Env1 :: cowboy_middleware:env().
Cowboy middleware, route the new request. Continue with the cowmachine, requests a redirect or return a 400 on an unknown host. The cowmachine_proxy middleware must have been called before this.
Fetch dispatch rules for a specific site.
-spec get_fallback_site() -> {ok, atom()} | undefined.
Retrieve the fallback site.
Fetch the site handling the given hostname (with optional port)
Fetch the site handling the given URL. Scheme is not checked.
Trap unknown calls
-spec handle_cast(term(), term()) -> {noreply, term()} | {noreply, term(), timeout() | hibernate} | {stop, term(), term()}.
Load all dispatch rules, if anything changed then recompile the dispatcher(s)
Handling all non call/cast messages
Initiates the server.
Callback for the dispatch compiler, try to bind a language
Starts the server
This function is called by a gen_server when it is about to terminate. It should be the opposite of Module:init/1 and do any necessary cleaning up. When it returns, the gen_server terminates with Reason. The return value is ignored.
-spec update_dispatchinfo() -> ok.
Collect dispatch information from all sites and recompiles the dispatch rules.
-spec update_hosts() -> ok.
Update the host/site mappings