Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable WASM support #877

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -31,6 +31,7 @@ logger = ["femme"]
docs = ["unstable"]
sessions = ["async-session", "cookies"]
unstable = []
wasm = []

[dependencies]
async-h1 = { version = "2.3.0", optional = true }
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Expand Up @@ -66,6 +66,7 @@
#[cfg(feature = "cookies")]
mod cookies;
mod endpoint;
#[cfg(not(feature = "wasm"))]
mod fs;
mod middleware;
mod redirect;
Expand All @@ -81,6 +82,7 @@ pub mod listener;
pub mod log;
pub mod prelude;
pub mod security;
#[cfg(not(feature = "wasm"))]
pub mod sse;
pub mod utils;

Expand Down
3 changes: 1 addition & 2 deletions src/listener/concurrent_listener.rs
Expand Up @@ -113,8 +113,7 @@ where
fn info(&self) -> Vec<ListenInfo> {
self.listeners
.iter()
.map(|listener| listener.info().into_iter())
.flatten()
.flat_map(|listener| listener.info().into_iter())
logankeenan marked this conversation as resolved.
Show resolved Hide resolved
.collect()
}
}
Expand Down
1 change: 1 addition & 0 deletions src/response.rs
Expand Up @@ -332,6 +332,7 @@ impl Response {
/// res.body_file("./archive.tgz").await?;
/// # Ok(()) }
/// ```
#[cfg(not(feature = "wasm"))]
pub async fn body_file(&mut self, path: impl AsRef<std::path::Path>) -> std::io::Result<()> {
self.set_body(Body::from_file(path).await?);
Ok(())
Expand Down
1 change: 1 addition & 0 deletions src/response_builder.rs
Expand Up @@ -181,6 +181,7 @@ impl ResponseBuilder {
/// assert_eq!(res.status(), 200);
/// # Ok(()) }
/// ```
#[cfg(not(feature = "wasm"))]
pub async fn body_file(self, path: impl AsRef<std::path::Path>) -> std::io::Result<Self> {
Ok(self.body(Body::from_file(path).await?))
}
Expand Down
3 changes: 3 additions & 0 deletions src/route.rs
Expand Up @@ -4,6 +4,7 @@ use std::path::Path;
use std::sync::Arc;

use crate::endpoint::MiddlewareEndpoint;
#[cfg(not(feature = "wasm"))]
use crate::fs::{ServeDir, ServeFile};
use crate::log;
use crate::{router::Router, Endpoint, Middleware};
Expand Down Expand Up @@ -163,6 +164,7 @@ impl<'a, State: Clone + Send + Sync + 'static> Route<'a, State> {
/// Ok(())
/// }
/// ```
#[cfg(not(feature = "wasm"))]
pub fn serve_dir(&mut self, dir: impl AsRef<Path>) -> io::Result<()> {
// Verify path exists, return error if it doesn't.
let dir = dir.as_ref().to_owned().canonicalize()?;
Expand All @@ -175,6 +177,7 @@ impl<'a, State: Clone + Send + Sync + 'static> Route<'a, State> {
///
/// The file will be streamed from disk, and a mime type will be determined
/// based on magic bytes. Similar to serve_dir
#[cfg(not(feature = "wasm"))]
pub fn serve_file(&mut self, file: impl AsRef<Path>) -> io::Result<()> {
self.get(ServeFile::init(file)?);
Ok(())
Expand Down