Skip to content

Commit

Permalink
Rename ftd.app-path -> ftd.app-url
Browse files Browse the repository at this point in the history
`fastn` touches both the file system (through its fs routing) and the
urls (since it's a webserver, duh). This might create a situation where
people think `ftd.app-path` is something related to fs but it's really
constructing the path relative to your website url. For this reason,
this has been renamed to `ftd.app-url` instead.
  • Loading branch information
siddhantk232 committed Feb 1, 2025
1 parent 8592d03 commit 0e5667c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
12 changes: 6 additions & 6 deletions fastn-core/src/host_builtins.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// Calling: `ftd.app-path(path = /test/)` in an ftd file of a mounted app will return the path
/// Calling: `ftd.app-url(path = /test/)` in an ftd file of a mounted app will return the path
/// prefixed with the `mountpoint` of the app.
///
/// The `path` arg must start with a forward slash (/)
Expand All @@ -17,7 +17,7 @@
///
/// ```some-test-app.fifthtry.site/index.ftd
///
/// -- ftd.text: $ftd.app-path(path = /test/)
/// -- ftd.text: $ftd.app-url(path = /test/)
/// ```
///
/// Visiting `/app/` in browser should render /app/test/
Expand All @@ -34,7 +34,7 @@ pub fn app_path(
.and_then(|a| a.package.system.clone())
.unwrap_or_default();

let name = "ftd#app-path".to_string();
let name = "ftd#app-url".to_string();
let def = fastn_resolved::Definition::Function(fastn_resolved::Function {
name: name.clone(),
return_kind: fastn_resolved::KindData {
Expand Down Expand Up @@ -71,7 +71,7 @@ pub fn app_path(
},
],
expression: vec![fastn_resolved::FunctionExpression {
expression: "ftd.app_path_ex(path, app)".to_string(),
expression: "ftd.app_url_ex(path, app)".to_string(),
line_number: 0,
}],
js: None,
Expand Down Expand Up @@ -109,10 +109,10 @@ pub fn main_package(config: &fastn_core::Config) -> (String, fastn_resolved::Def

/// Ftd string variable that holds the `fastn.app` mounts
///
/// Used by `ftd.app-path` to determine the mountpoint of the app
/// Used by `ftd.app-url` to determine the mountpoint of the app
#[inline]
pub fn app_mounts(config: &fastn_core::Config) -> (String, fastn_resolved::Definition) {
let name = "ftd#app-mounts".to_string();
let name = "ftd#app-urls".to_string();
let variants = config
.app_mounts()
.unwrap_or_default()
Expand Down
6 changes: 3 additions & 3 deletions fastn-js/js/ftd.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const ftd = (function () {
exports.is_app_mounted = (app) => {
if (app instanceof fastn.mutableClass) app = app.get();
app = app.replaceAll("-", "_");
return !!ftd.app_mounts.get(app);
return !!ftd.app_urls.get(app);
};

/**
Expand All @@ -73,15 +73,15 @@ const ftd = (function () {
*
* @returns {string}
*/
exports.app_path_ex = (path, app) => {
exports.app_url_ex = (path, app) => {
if (path instanceof fastn.mutableClass)
path = fastn_utils.getStaticValue(path);
if (app instanceof fastn.mutableClass)
app = fastn_utils.getStaticValue(app);

app = app.replaceAll("-", "_");

let prefix = ftd.app_mounts.get(app)?.get() || "";
let prefix = ftd.app_urls.get(app)?.get() || "";

if (prefix.length > 0 && prefix.charAt(prefix.length - 1) === "/") {
prefix = prefix.substring(0, prefix.length - 1);
Expand Down
8 changes: 4 additions & 4 deletions fastn.com/backend/app.ftd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The above snippet will mount contents of [lets-auth.fifthtry.site](https://lets-

Visiting `/-/auth/` will load `index.ftd` of lets-auth.fifthtry.site if it's available.

-- ds.h2: `ftd.app-path` function
-- ds.h2: `ftd.app-url` function

This functions let's apps construct paths relative to their mountpoint. For
example, `lets-auth.fifthtry.site/index.ftd` could show a url to its signin
Expand All @@ -26,11 +26,11 @@ page (`lets-auth.fifthtry.site/signin.ftd`) using the following code:
lang: ftd

\-- ftd.text: Sign In
link: $ftd.app-path(path = /signin/) \;; will become /-/auth/signin/
link: $ftd.app-url(path = /signin/) \;; will become /-/auth/signin/

-- ds.markdown:

A second `app` parameter can be passed to `ftd.app-path` function to construct
A second `app` parameter can be passed to `ftd.app-url` function to construct
urls for other mounted apps. Consider the following FASTN.ftd file:


Expand Down Expand Up @@ -63,6 +63,6 @@ A file in `lets-auth.fifthtry.site` can construct a path that is relative to the
lang: ftd

\-- ftd.text: Go to design system docs homepage
link: $ftd.app-path(path = /docs/, app = ds) ;; `ds` is the system name of design-system.fifthtry.site
link: $ftd.app-url(path = /docs/, app = ds) ;; `ds` is the system name of design-system.fifthtry.site

-- end: ds.page
6 changes: 3 additions & 3 deletions fastn.com/ftd/built-in-functions.ftd
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,9 @@ or empty.

-- end: ds.rendered

-- ds.h2: `app-path(path: string, app: string)`
-- ds.h2: `app-url(path: string, app: string)`

Calling `ftd.app-path(path = /test/)` in an ftd file of a mounted app will
Calling `ftd.app-url(path = /test/)` in an ftd file of a mounted app will
return the path prefixed with the `mountpoint` of the app.

The second parameter (`app`) can be used to construct paths for other mounted
Expand All @@ -671,7 +671,7 @@ package: some-test-app.fifthtry.site
-- ds.code: some-test-app.fifthtry.site/index.ftd
lang: ftd

\-- ftd.text: $ftd.app-path(path = /test/)
\-- ftd.text: $ftd.app-url(path = /test/)


-- ds.markdown: Visiting `/app/` in browser should render text "/app/test/"
Expand Down
2 changes: 1 addition & 1 deletion ftd/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn default_bag_into_js_ast() -> Vec<fastn_js::Ast> {
ftd_asts
}

const IGNORE_GLOBAL: [&str; 2] = ["ftd#main-package", "ftd#app-mounts"];
const IGNORE_GLOBAL: [&str; 2] = ["ftd#main-package", "ftd#app-urls"];

#[derive(Debug)]
pub struct JSAstData {
Expand Down

0 comments on commit 0e5667c

Please sign in to comment.