forked from
microcosm.blue/microcosm-rs
Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm
1use dropshot::{HttpError, HttpResponseHeaders, HttpResponseOk};
2use schemars::JsonSchema;
3use serde::Serialize;
4
5pub type OkCorsResponse<T> = Result<HttpResponseHeaders<HttpResponseOk<T>>, HttpError>;
6
7/// Helper for constructing Ok responses: return OkCors(T).into()
8/// (not happy with this yet)
9pub struct OkCors<T: Serialize + JsonSchema + Send + Sync>(pub T);
10
11impl<T> From<OkCors<T>> for OkCorsResponse<T>
12where
13 T: Serialize + JsonSchema + Send + Sync,
14{
15 fn from(ok: OkCors<T>) -> OkCorsResponse<T> {
16 let mut res = HttpResponseHeaders::new_unnamed(HttpResponseOk(ok.0));
17 res.headers_mut()
18 .insert("access-control-allow-origin", "*".parse().unwrap());
19 Ok(res)
20 }
21}
22
23// TODO: cors for HttpError