Skip to content

Commit

Permalink
Move bundle into web utility module
Browse files Browse the repository at this point in the history
  • Loading branch information
TimJentzsch committed Dec 23, 2024
1 parent bb3627f commit 953e833
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pub mod external_cli;
pub mod lint;
pub mod run;
pub mod template;
pub(crate) mod web;
3 changes: 1 addition & 2 deletions src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ use std::path::PathBuf;

use anyhow::Context;
use args::RunSubcommands;
use bundle::create_web_bundle;

use crate::{
build::ensure_web_setup,
external_cli::{
cargo::{self, metadata::Metadata},
wasm_bindgen, CommandHelpers,
},
web::bundle::create_web_bundle,
};

pub use self::args::RunArgs;

mod args;
mod bundle;
mod serve;

pub fn run(args: &RunArgs) -> anyhow::Result<()> {
Expand Down
6 changes: 3 additions & 3 deletions src/run/serve.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Serving the app locally for the browser.
use actix_web::{rt, web, App, HttpResponse, HttpServer, Responder};

use super::bundle::{LinkedBundle, PackedBundle, WebBundle};
use crate::web::bundle::{Index, LinkedBundle, PackedBundle, WebBundle};

/// Serve a static HTML file with the given content.
async fn serve_static_html(content: &'static str) -> impl Responder {
Expand Down Expand Up @@ -50,12 +50,12 @@ pub(crate) fn serve(web_bundle: WebBundle, port: u16) -> anyhow::Result<()> {
}

match index {
super::bundle::Index::Folder(path) => {
Index::Folder(path) => {
app = app.service(
actix_files::Files::new("/", path).index_file("index.html"),
);
}
super::bundle::Index::Static(contents) => {
Index::Static(contents) => {
app = app.route("/", web::get().to(move || serve_static_html(contents)))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/run/bundle.rs → src/web/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
path::{Path, PathBuf},
};

use super::{cargo::metadata::Metadata, BinTarget};
use crate::{external_cli::cargo::metadata::Metadata, run::BinTarget};

#[derive(Debug, Clone)]
pub enum Index {
Expand Down
3 changes: 3 additions & 0 deletions src/web/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! Utilities for building and running the app in the browser.
pub(crate) mod bundle;

0 comments on commit 953e833

Please sign in to comment.