32 lines
725 B
Rust
32 lines
725 B
Rust
use tower_http::cors::{Any, CorsLayer};
|
|
use tower_service::Service;
|
|
use worker::*;
|
|
|
|
mod auth;
|
|
mod crypto;
|
|
mod db;
|
|
mod error;
|
|
mod handlers;
|
|
mod models;
|
|
mod router;
|
|
|
|
#[event(fetch)]
|
|
pub async fn main(
|
|
req: HttpRequest,
|
|
env: Env,
|
|
_ctx: Context,
|
|
) -> Result<axum::http::Response<axum::body::Body>> {
|
|
// Set up logging
|
|
console_error_panic_hook::set_once();
|
|
let _ = console_log::init_with_level(log::Level::Debug);
|
|
|
|
// Allow all origins for CORS, which is typical for a public API like Bitwarden's.
|
|
let cors = CorsLayer::new()
|
|
.allow_methods(Any)
|
|
.allow_headers(Any)
|
|
.allow_origin(Any);
|
|
|
|
let mut app = router::api_router(env).layer(cors);
|
|
|
|
Ok(app.call(req).await?)
|
|
}
|