Skip to content

mehmetcansahin/waserv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Waserv - work in progress

crates.io Released API docs GHA Build Status

Waserv is a simple web server for a wasm

Request -> Cloudflare Worker -> Waserv -> Response

## Example

use web_sys::{Request, Response, Headers};
use waserv::{response::response, router::Router, Params, Waserv};

fn index(_request: Request, _params: Params) -> Response {
    let body = "Hello, World!".to_string();
    let headers = Headers::new().unwrap();
    headers
        .set("Content-Type", "text/html; charset=UTF-8")
        .unwrap();
    headers.set("Cache-Control", "no-cache").unwrap();
    response(body, headers, Some(200))
}

fn handle(request: Request) -> Response {
    let mut router = Router::new();
    router.get("/", Box::new(index));
    let mut ww = Waserv::new();
    ww.mount(router);
    ww.handle(request)
}

Test

wasm-pack test --chrome

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages