Compare commits

...

2 commits

Author SHA1 Message Date
a572ca0d7c
IS THIS DONE YET? 2020-01-27 10:05:54 +01:00
ab603643c9
Actually parse address 2020-01-24 16:51:05 +01:00
5 changed files with 796 additions and 846 deletions

1554
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -13,8 +13,11 @@ chrono = "0.4"
clap = "2.33" clap = "2.33"
walkdir = "2" walkdir = "2"
juniper = "0.14" juniper = "0.14"
juniper_warp = "0.5.2" serde = "1.0.103"
warp = "0.1.8" serde_json = "1.0.44"
actix-web = "2.0.0"
actix-rt = "1.0.0"
actix-cors = "0.2.0"
[dependencies.rusqlite] [dependencies.rusqlite]
version = "0.21.0" version = "0.21.0"

View file

@ -2,11 +2,15 @@ extern crate juniper;
use crate::database::{DBLog, DBMessage}; use crate::database::{DBLog, DBMessage};
use chrono::prelude::*; use chrono::prelude::*;
use juniper::http::GraphQLRequest;
use juniper::Value::Null; use juniper::Value::Null;
use juniper::{FieldError, FieldResult}; use juniper::{FieldError, FieldResult};
use std::collections::HashSet; use std::collections::HashSet;
use std::convert::TryInto; use std::convert::TryInto;
use warp::Filter; use std::sync::Arc;
use actix_cors::Cors;
use actix_web::{http, middleware, web, App, Error, HttpResponse, HttpServer};
#[derive(Debug, juniper::GraphQLObject)] #[derive(Debug, juniper::GraphQLObject)]
#[graphql(description = "Paginated list of messages")] #[graphql(description = "Paginated list of messages")]
@ -248,18 +252,52 @@ impl Mutation {}
type Schema = juniper::RootNode<'static, Query, Mutation>; type Schema = juniper::RootNode<'static, Query, Mutation>;
pub fn server(databases: Vec<DBLog>) { async fn graphql(
let schema = Schema::new(Query, Mutation); st: web::Data<Arc<GQLData>>,
let state = warp::any().map(move || Context { data: web::Json<GraphQLRequest>,
databases: databases.clone().into_iter().map(from_db).collect(), ) -> Result<HttpResponse, Error> {
}); let user = web::block(move || {
let graphql_filter = juniper_warp::make_graphql_filter(schema, state.boxed()); let res = data.execute(&st.schema, &st.context);
Ok::<_, serde_json::error::Error>(serde_json::to_string(&res)?)
warp::serve( })
warp::get2() .await?;
.and(warp::path("graphiql")) Ok(HttpResponse::Ok()
.and(juniper_warp::graphiql_filter("/graphql")) .content_type("application/json")
.or(warp::path("graphql").and(graphql_filter)), .body(user))
) }
.run(([127, 0, 0, 1], 8080));
struct GQLData {
schema: Schema,
context: Context,
}
pub async fn server(bind: &str, databases: Vec<DBLog>) -> std::io::Result<()> {
// Create Juniper schema
let schema = Schema::new(Query, Mutation);
let context = Context {
databases: databases.into_iter().map(from_db).collect(),
};
let data = std::sync::Arc::new(GQLData { schema, context });
// Start http server
HttpServer::new(move || {
App::new()
.data(data.clone())
.wrap(middleware::Logger::default())
.wrap(
Cors::new()
.allowed_methods(vec!["GET", "POST", "OPTIONS"])
.allowed_headers(vec![
http::header::AUTHORIZATION,
http::header::ACCEPT,
http::header::CONTENT_TYPE,
])
.max_age(3600)
.finish(),
)
.service(web::resource("/graphql").route(web::post().to(graphql)))
})
.bind(bind)?
.run()
.await
} }

View file

@ -5,7 +5,8 @@ use clap::{App, Arg};
use database::scan_dbs; use database::scan_dbs;
use graphql::server; use graphql::server;
fn main() -> std::io::Result<()> { #[actix_rt::main]
async fn main() -> std::io::Result<()> {
let cmd = App::new("Riplog") let cmd = App::new("Riplog")
.version("1.0") .version("1.0")
.arg( .arg(
@ -21,14 +22,13 @@ fn main() -> std::io::Result<()> {
.required(true) .required(true)
.short("b") .short("b")
.help("Address to bind to") .help("Address to bind to")
.default_value("127.0.0.1:9743") .default_value("127.0.0.1:8080"),
.index(2),
) )
.get_matches(); .get_matches();
let basedir = cmd.value_of("basedir").unwrap(); let basedir = cmd.value_of("basedir").unwrap();
let addr = cmd.value_of("bind").unwrap();
let logs = scan_dbs(basedir); let logs = scan_dbs(basedir);
println!("Loaded data for {} workspaces", logs.len()); println!("Loaded data for {} workspaces", logs.len());
server(logs); server(addr, logs).await
Ok(())
} }

3
frontend/.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
node_modules
.cache
dist