Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,033 changes: 2,874 additions & 159 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ indoc = "2"
itertools = "0.14"
mime_guess = "2"
once_cell = "1"
pista-lib = { path = "../pista/pista-lib" }
prettify-js = "0.1.0"
pretty = "0.12"
pretty_assertions = "1"
Expand All @@ -129,10 +130,15 @@ serde_json = "1"
sha2 = "0.10"
slug = "0.1"
snafu = "0.8"
tempfile = "3"
thiserror = "2"
tokio = { version = "1", features = ["full"] }
tokio-postgres = { version = "0.7", features = ["with-serde_json-1", "with-uuid-1"] }
tracing = "0.1"
tauri = "2.6"
tauri-macros = "2"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tauri-build = { version = "2", features = ["config-json5"] }
url = "2"
walkdir = "2"
wasmtime = "34"
Expand Down
3 changes: 0 additions & 3 deletions fastn-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ async-trait.workspace = true
bytes.workspace = true
camino.workspace = true
chrono.workspace = true
clap.workspace = true
colored.workspace = true
deadpool.workspace = true
diffy.workspace = true
dirs.workspace = true
env_logger.workspace = true
fastn-ds.workspace = true
fastn-expr.workspace = true
fastn-js.workspace = true
Expand All @@ -43,7 +41,6 @@ futures-core.workspace = true
futures-util.workspace = true
futures.workspace = true
http.workspace = true
ignore.workspace = true
indoc.workspace = true
itertools.workspace = true
mime_guess.workspace = true
Expand Down
61 changes: 3 additions & 58 deletions fastn-core/src/commands/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,68 +707,13 @@ async fn actual_route(
.map(|(r, _)| r)
}

/// Handle the request by serving .ftd or static files.
/// Also supports .wasm modules written with ft_sdk
#[tracing::instrument(skip_all)]
async fn route(
pub async fn route_handler(
req: actix_web::HttpRequest,
body: actix_web::web::Bytes,
config: actix_web::web::Data<std::sync::Arc<fastn_core::Config>>,
) -> fastn_core::Result<fastn_core::http::Response> {
actual_route(&config, req, body, &None).await
}

#[allow(clippy::too_many_arguments)]
pub async fn listen(
config: std::sync::Arc<fastn_core::Config>,
bind_address: &str,
port: Option<u16>,
) -> fastn_core::Result<()> {
use colored::Colorize;
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));

let tcp_listener = match fastn_core::http::get_available_port(port, bind_address) {
Some(listener) => listener,
None => {
eprintln!(
"{}",
port.map(|x| format!(
r#"Provided port {} is not available.

You can try without providing port, it will automatically pick unused port."#,
x.to_string().red()
))
.unwrap_or_else(|| {
"Tried picking port between port 8000 to 9000, none are available :-("
.to_string()
})
);
std::process::exit(2);
}
};

let app = move || {
actix_web::App::new()
.app_data(actix_web::web::Data::new(std::sync::Arc::clone(&config)))
.app_data(actix_web::web::PayloadConfig::new(1024 * 1024 * 10))
.wrap(actix_web::middleware::Compress::default())
.wrap(fastn_core::catch_panic::CatchPanic::default())
.wrap(
actix_web::middleware::Logger::new(
r#""%r" %Ts %s %b %a "%{Referer}i" "%{User-Agent}i""#,
)
.log_target(""),
)
.route("/{path:.*}", actix_web::web::route().to(route))
};

println!("### Server Started ###");
println!(
"Go to: http://{}:{}",
bind_address,
tcp_listener.local_addr()?.port()
);
actix_web::HttpServer::new(app)
.listen(tcp_listener)?
.run()
.await?;
Ok(())
}
18 changes: 15 additions & 3 deletions fastn-core/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ fn cached_parse(
doc: ftd::interpreter::ParsedDocument,
}

let hash = fastn_core::utils::generate_hash(source);

/* if let Some(c) = fastn_core::utils::get_cached::<C>(id) {
if c.hash == hash {
tracing::debug!("cache hit");
Expand All @@ -22,7 +20,21 @@ fn cached_parse(
}*/

let doc = ftd::interpreter::ParsedDocument::parse_with_line_number(id, source, line_number)?;
fastn_core::utils::cache_it(id, C { doc, hash }).map(|v| v.doc)

// TODO: handle caching on mobile
// This does not work yet as the `fastn_core::utils::cache_it` function is not can't make a
// cache dir using the `dirs` crate. We have to get the cache dir from tauri/fastn (outside
// fastn-core crate)
#[cfg(target_os = "android")]
{
return Ok(doc);
}

#[cfg(not(target_os = "android"))]
{
let hash = fastn_core::utils::generate_hash(source);
return fastn_core::utils::cache_it(id, C { doc, hash }).map(|v| v.doc);
}
}

pub fn package_dependent_builtins(
Expand Down
3 changes: 0 additions & 3 deletions fastn-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ pub enum Error {
#[error("FTDHtmlError: {}", _0)]
FTDHtmlError(#[from] ftd::html::Error),

#[error("IgnoreError: {}", _0)]
IgnoreError(#[from] ignore::Error),

#[error("FromPathBufError: {}", _0)]
FromPathBufError(#[from] camino::FromPathBufError),

Expand Down
20 changes: 0 additions & 20 deletions fastn-core/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,26 +513,6 @@ pub async fn http_get_with_cookie(
Ok((Ok(res.body().clone()), resp_cookies))
}

pub(crate) fn get_available_port(
port: Option<u16>,
bind_address: &str,
) -> Option<std::net::TcpListener> {
let available_listener =
|port: u16, bind_address: &str| std::net::TcpListener::bind((bind_address, port));

if let Some(port) = port {
return available_listener(port, bind_address).ok();
}

for x in 8000..9000 {
match available_listener(x, bind_address) {
Ok(l) => return Some(l),
Err(_) => continue,
}
}
None
}

/// construct `ftd.http` consumable error responses
/// https://github.com/fastn-stack/fastn/blob/7f0b79a/fastn-js/js/ftd.js#L218C45-L229
/// ```json
Expand Down
2 changes: 1 addition & 1 deletion fastn-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub(crate) mod host_builtins;

pub(crate) use auto_import::AutoImport;
pub use commands::{
build::build, check::post_build_check, fmt::fmt, query::query, serve::listen, test::test,
build::build, check::post_build_check, fmt::fmt, query::query, serve::route_handler, test::test,
};
pub use config::{Config, ConfigTemp, FTDEdition, RequestConfig, config_temp};
pub use doc::resolve_foreign_variable2;
Expand Down
2 changes: 1 addition & 1 deletion fastn-core/src/sitemap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ impl Sitemap {
Ok(())
}

#[async_recursion::async_recursion(?Send)]
#[async_recursion::async_recursion]
async fn resolve_toc(
toc: &mut toc::TocItem,
package_root: &fastn_ds::Path,
Expand Down
16 changes: 0 additions & 16 deletions fastn-core/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
pub trait ValueOf {
fn value_of_(&self, name: &str) -> Option<&str>;
fn values_of_(&self, name: &str) -> Vec<String>;
}

impl ValueOf for clap::ArgMatches {
fn value_of_(&self, name: &str) -> Option<&str> {
self.get_one::<String>(name).map(|v| v.as_str())
}
fn values_of_(&self, name: &str) -> Vec<String> {
self.get_many(name)
.map(|v| v.cloned().collect::<Vec<String>>())
.unwrap_or_default()
}
}

// https://stackoverflow.com/questions/71985357/whats-the-best-way-to-write-a-custom-format-macro
#[macro_export]
macro_rules! warning {
Expand Down
32 changes: 24 additions & 8 deletions fastn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,36 @@ default = ["fifthtry", "use-config-json"]
fifthtry = ["clift"]
use-config-json = []

[lib]
name = "fastn_lib"
crate-type = ["staticlib", "cdylib", "rlib"]

[dependencies]
clift = { workspace = true, optional = true }
actix-web.workspace = true
camino.workspace = true
clap.workspace = true
clift = { workspace = true, optional = true }
deadpool-postgres.workspace = true
dirs.workspace = true
dotenvy.workspace = true
env_logger.workspace = true
fastn-core.workspace = true
fastn-ds.workspace = true
fastn-observer.workspace = true
fastn-update.workspace = true
fastn-core.workspace = true
futures.workspace = true
pista-lib.workspace = true
reqwest.workspace = true
scc.workspace = true
serde.workspace = true
tauri-macros.workspace = true
tauri.workspace = true
tempfile.workspace = true
thiserror.workspace = true
tokio.workspace = true
dotenvy.workspace = true
fastn-ds.workspace = true
camino.workspace = true
actix-web.workspace = true
scc.workspace = true
deadpool-postgres.workspace = true
tracing-subscriber.workspace = true
tracing.workspace = true
zip.workspace = true

[build-dependencies]
tauri-build.workspace = true
3 changes: 3 additions & 0 deletions fastn/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}
11 changes: 11 additions & 0 deletions fastn/capabilities/default.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "enables the default permissions",
"windows": [
"main"
],
"permissions": [
"core:default"
]
}
12 changes: 12 additions & 0 deletions fastn/gen/android/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = true
19 changes: 19 additions & 0 deletions fastn/gen/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
build
/captures
.externalNativeBuild
.cxx
local.properties
key.properties

/.tauri
/tauri.settings.gradle
6 changes: 6 additions & 0 deletions fastn/gen/android/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/src/main/java/com/fastn/generated
/src/main/jniLibs/**/*.so
/src/main/assets/tauri.conf.json
/tauri.build.gradle.kts
/proguard-tauri.pro
/tauri.properties
Loading
Loading