my-canister-frontend

Crates.iomy-canister-frontend
lib.rsmy-canister-frontend
version0.2.1
created_at2025-07-16 13:24:00.366289+00
updated_at2025-09-11 08:54:14.535887+00
descriptionFrontend asset utilities Canister Dapps
homepage
repositoryhttps://github.com/Web3NL/my-canister-dapp/tree/main/my-canister-dapp-rs/my-canister-frontend
max_upload_size
id1755497
size44,977
Samer (Web3NL)

documentation

https://docs.rs/my-canister-frontend

README

My Canister Frontend

Crates.io Documentation Build Status License: MIT

Frontend asset processing library for Internet Computer Canister Dapps.

Usage

Single canister example:

use ic_cdk::{init, query};
use ic_http_certification::{HttpRequest, HttpResponse};
use include_dir::{include_dir, Dir};
use my_canister_frontend::setup_frontend;

static ASSETS: Dir = include_dir!("$CARGO_MANIFEST_DIR/../dapp-frontend/dist");

#[init]
fn init() {
	setup_frontend(&ASSETS);
}

#[query]
fn http_request(req: HttpRequest) -> HttpResponse {
	my_canister_frontend::http_request(req)
}

Features

  • Implements internal AssetRouter for managing frontend assets
  • Embeds assets provided a Dir via include_dir
  • Automatic MIME type detection using mime_guess
  • index.html auto-configured as fallback for /
  • Certification using ic-asset-certification
  • Exposes with_asset_router and with_asset_router_mut for access to the asset router, see example below.
  • Exposes asset_router_configs if you want to implement your own asset router, see this example.

Usage with my_canister_dashboard

use ic_cdk::{init, query};
use ic_http_certification::{HttpRequest, HttpResponse};
use include_dir::{include_dir, Dir};
use my_canister_dashboard::setup_dashboard_assets;
use my_canister_frontend::setup_frontend;
use my_canister_frontend::asset_router::with_asset_router_mut;

static ASSETS: Dir = include_dir!("$CARGO_MANIFEST_DIR/../dapp-frontend/dist");

#[init]
fn init() {
	setup_frontend(&ASSETS);

    // Setup dashboard in internal asset router
    with_asset_router_mut(|router| {
        setup_dashboard_assets(
            router,
            Some(vec![
                "https://mycanister.app".to_string(),
            ]),
        );
    });
}

#[query]
fn http_request(req: HttpRequest) -> HttpResponse {
	my_canister_frontend::http_request(req)
}

License

MIT

Commit count: 585

cargo fmt