add basiv webview for font results

This commit is contained in:
lauchmelder 2025-03-05 18:09:51 +01:00
parent fae5f783f3
commit eea4fad2bd
3 changed files with 107 additions and 4 deletions

View file

@ -1,9 +1,28 @@
#[macro_use] extern crate rocket;
use std::{fs::File, net::{IpAddr, Ipv4Addr}, sync::Mutex};
use std::{fs::File, future::Future, net::{IpAddr, Ipv4Addr}, sync::Mutex};
use fontloader::{writer::Visitor, Font, SvgWriter};
use rocket::{response::{content, status}, Config, State};
use rocket::{fairing::{Fairing, Info, Kind}, http::Header, response::{content, status}, Config, State};
struct CORS;
#[rocket::async_trait]
impl Fairing for CORS {
fn info(&self) -> Info {
Info {
name: "Adding CORS headers to responses",
kind: Kind::Response
}
}
async fn on_response<'r>(&self, _req: &'r rocket::Request<'_>, response: &mut rocket::Response<'r>) {
response.set_header(Header::new("Access-Control-Allow-Origin", "*"));
response.set_header(Header::new("Access-Control-Allow-Methods", "POST, GET, PATCH, OPTIONS"));
response.set_header(Header::new("Access-Control-Allow-Headers", "*"));
response.set_header(Header::new("Access-Control-Allow-Credentials", "true"));
}
}
struct SharedFont {
font: Mutex<Font>
@ -43,4 +62,5 @@ fn rocket() -> _ {
rocket::custom(config)
.manage(SharedFont { font: Mutex::from(font) })
.mount("/", routes![get_glyph])
.attach(CORS)
}