```rust #[event(fetch)] async fn fetch(req: HttpRequest, _env: Env, _ctx: Context) -> Result<Respons

#[event(fetch)]
async fn fetch(req: HttpRequest, _env: Env, _ctx: Context) -> Result<Response<Body>> {
    console_error_panic_hook::set_once();

    let cors = CorsLayer::new()
        .allow_origin("https://shorter.dev".parse::<HeaderValue>().unwrap())
        .allow_headers([CONTENT_TYPE])
        .allow_methods([Method::GET, Method::POST, Method::HEAD, Method::OPTIONS]);

    let app = Router::new()
        .route("/", get(|| async { "shorter.dev server!" }))
        .merge(mount())
        .layer(cors)
        .call(req)
        .await?;

    Ok(app)
}
Was this page helpful?