Ensure CORS headers are set on failed HTTP responses

Closes #6
This commit is contained in:
Tobie Morgan Hitchcock 2022-07-23 13:49:26 +01:00
parent a71562df9f
commit 428fcf697a
5 changed files with 6 additions and 8 deletions

View file

@ -1,6 +1,5 @@
use crate::dbs::DB;
use crate::err::Error;
use crate::net::head;
use crate::net::output;
use crate::net::session;
use bytes::Bytes;
@ -112,7 +111,7 @@ pub fn config() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejecti
// ------------------------------
// Specify route
opts.or(all).or(one).with(head::cors())
opts.or(all).or(one)
}
// ------------------------------

View file

@ -54,6 +54,8 @@ pub async fn init() -> Result<(), Error> {
let net = net.with(head::version());
// Specify a generic server header
let net = net.with(head::server());
// Set cors headers on all requests
let net = net.with(head::cors());
// Log all requests to the console
let net = net.with(log::write());

View file

@ -1,5 +1,4 @@
use crate::err::Error;
use crate::net::head;
use bytes::Bytes;
use std::str;
use surrealdb::sql::Value;
@ -20,7 +19,7 @@ pub fn config() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejecti
.and(warp::body::bytes())
.and_then(handler);
// Specify route
opts.or(post).with(head::cors())
opts.or(post)
}
async fn handler(body: Bytes) -> Result<impl warp::Reply, warp::Rejection> {

View file

@ -1,5 +1,4 @@
use crate::err::Error;
use crate::net::head;
use bytes::Bytes;
use std::str;
use surrealdb::sql::Value;
@ -20,7 +19,7 @@ pub fn config() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejecti
.and(warp::body::bytes())
.and_then(handler);
// Specify route
opts.or(post).with(head::cors())
opts.or(post)
}
async fn handler(body: Bytes) -> Result<impl warp::Reply, warp::Rejection> {

View file

@ -1,6 +1,5 @@
use crate::dbs::DB;
use crate::err::Error;
use crate::net::head;
use crate::net::output;
use crate::net::session;
use bytes::Bytes;
@ -30,7 +29,7 @@ pub fn config() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejecti
.and(session::build())
.map(|ws: Ws, session: Session| ws.on_upgrade(move |ws| socket(ws, session)));
// Specify route
opts.or(post).or(sock).with(head::cors())
opts.or(post).or(sock)
}
async fn handler(