1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! Resolving URLs for the application's frontends.
//!
//! Call [`url`] to get a frontend's base URL in the current environment, for
//! example to redirect users or construct links to frontend pages:
//!
//! ```ignore
//! use encore::frontends;
//!
//! let reset = format!("{}/reset?token={token}", frontends::url("web"));
//! ```
//!
//! Looking up a frontend URL records a dependency from the calling service to
//! that frontend. Because Encore parses this dependency statically, pass the
//! frontend's declared name as a string literal, call `frontends::url` directly
//! (rather than through a function pointer), and make the call inside a service.
/// Returns the base URL for `frontend` in the current environment, without a
/// trailing slash (so paths can be appended directly, e.g. `{url}/reset`).
///
/// This returns the first origin listed for the frontend in
/// [`crate::env::app_meta`]. `frontend` must match the exact name declared in
/// `encore.frontend.json` or the hosting service (for example, `web_app` does
/// not match `web-app`).
///
/// # Panics
///
/// Panics if no URL is configured for `frontend` — either because the app has
/// no frontend with that name or because the environment provides no origins
/// for it.