use axum::{Router, routing::get};
use ocre::{ApiError, Ctx, Error, Json};
use serde::Serialize;
use worker::{Context, Env, HttpRequest, event};
#[event(start)]
fn start() {}
#[event(fetch)]
async fn fetch(req: HttpRequest, env: Env, _ctx: Context) -> worker::Result<worker::web_sys::Response> {
ocre::serve(routes(), req, env).await
}
fn routes() -> Router<Ctx> {
Router::new()
.route("/", get(status))
.route("/up", get(up))
.fallback(not_found)
}
#[derive(Serialize)]
struct Status {
app: &'static str,
status: &'static str,
}
async fn status() -> Json<Status> {
Json(Status { app: "__APP_NAME__", status: "ok" })
}
async fn up() -> &'static str {
"OK"
}
async fn not_found() -> ApiError {
ApiError(Error::NotFound)
}