Basic frontend Axum server

main
~erin 2023-07-25 23:24:29 -04:00
parent 09b56b5096
commit 94056699d2
Signed by: erin
GPG Key ID: 0FEDEAFF1C14847E
6 changed files with 53 additions and 18 deletions

14
Cargo.lock generated
View File

@ -387,16 +387,14 @@ checksum = "795bc6e66a8e340f075fcf6227e417a2dc976b92b91f3cdc778bb858778b6747"
[[package]]
name = "core"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"ammonia",
"axum",
"chrono",
"config",
"dirs",
"env_logger",
"fuzzy-matcher",
"log",
"scraper",
"serde",
"serde_json",
@ -727,6 +725,16 @@ dependencies = [
[[package]]
name = "frontend"
version = "0.1.0"
dependencies = [
"axum",
"chrono",
"config",
"dirs",
"tokio",
"tracing",
"tracing-subscriber",
"url",
]
[[package]]
name = "futf"

View File

@ -18,6 +18,8 @@ chrono = { version = "0.4.26", features = [ "serde" ] }
sqlx = { version = "0.7", features = [ "runtime-tokio", "tls-rustls", "chrono", "macros", "sqlite" ] }
scraper = "0.17.1"
axum = { version = "0.6.19", features = [ "http2", "tracing" ] }
tracing-subscriber = "0.3.17"
tracing = "0.1.37"
[profile.release]
strip = true

View File

@ -7,8 +7,6 @@ homepage.workspace = true
license.workspace = true
[dependencies]
log.workspace = true
env_logger.workspace = true
tokio.workspace = true
sqlx.workspace = true
chrono.workspace = true
@ -17,10 +15,10 @@ dirs.workspace = true
scraper.workspace = true
axum.workspace = true
url.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
whatlang = "0.16.2"
ammonia = "3"
tracing-subscriber = "0.3.17"
tracing = "0.1.37"
serde = "1.0.175"
serde_json = "1.0.103"
fuzzy-matcher = "0.3.7"

View File

@ -1,6 +1,3 @@
#[macro_use]
extern crate log;
use ammonia::clean;
use axum::{
body::Bytes,
@ -38,8 +35,6 @@ async fn main() {
let shared_state = Arc::new(AppState { pool: pool });
let app = Router::new()
// `GET /` goes to `root`
.route("/", get(root))
.route("/api/search", get(search))
.with_state(shared_state);
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
@ -51,10 +46,6 @@ async fn main() {
.unwrap();
}
async fn root() -> &'static str {
"Hello, World!"
}
#[derive(Deserialize)]
struct SearchQuery {
language: String,

View File

@ -5,3 +5,13 @@ edition.workspace = true
authors.workspace = true
homepage.workspace = true
license.workspace = true
[dependencies]
tokio.workspace = true
chrono.workspace = true
config.workspace = true
dirs.workspace = true
axum.workspace = true
url.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true

View File

@ -1,3 +1,29 @@
fn main() {
println!("Hello, world!");
use axum::{
body::Bytes,
extract::State,
http::StatusCode,
response::IntoResponse,
routing::{get, post},
Json, Router,
};
use chrono::{DateTime, NaiveDateTime, Utc};
use std::net::SocketAddr;
use url::Url;
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
let app = Router::new().route("/", get(root));
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
tracing::debug!("listening on {}", addr);
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
}
async fn root() -> &'static str {
"Hello, World!"
}