Compare commits
No commits in common. "a572ca0d7cd8acd47cfd0c034336a5b608f5bf01" and "c33e3051367c23384511bac55bb98c1533455f3d" have entirely different histories.
a572ca0d7c
...
c33e305136
5 changed files with 848 additions and 798 deletions
1562
Cargo.lock
generated
1562
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -13,11 +13,8 @@ chrono = "0.4"
|
||||||
clap = "2.33"
|
clap = "2.33"
|
||||||
walkdir = "2"
|
walkdir = "2"
|
||||||
juniper = "0.14"
|
juniper = "0.14"
|
||||||
serde = "1.0.103"
|
juniper_warp = "0.5.2"
|
||||||
serde_json = "1.0.44"
|
warp = "0.1.8"
|
||||||
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"
|
||||||
|
|
|
@ -2,15 +2,11 @@ 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 std::sync::Arc;
|
use warp::Filter;
|
||||||
|
|
||||||
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")]
|
||||||
|
@ -252,52 +248,18 @@ impl Mutation {}
|
||||||
|
|
||||||
type Schema = juniper::RootNode<'static, Query, Mutation>;
|
type Schema = juniper::RootNode<'static, Query, Mutation>;
|
||||||
|
|
||||||
async fn graphql(
|
pub fn server(databases: Vec<DBLog>) {
|
||||||
st: web::Data<Arc<GQLData>>,
|
|
||||||
data: web::Json<GraphQLRequest>,
|
|
||||||
) -> Result<HttpResponse, Error> {
|
|
||||||
let user = web::block(move || {
|
|
||||||
let res = data.execute(&st.schema, &st.context);
|
|
||||||
Ok::<_, serde_json::error::Error>(serde_json::to_string(&res)?)
|
|
||||||
})
|
|
||||||
.await?;
|
|
||||||
Ok(HttpResponse::Ok()
|
|
||||||
.content_type("application/json")
|
|
||||||
.body(user))
|
|
||||||
}
|
|
||||||
|
|
||||||
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 schema = Schema::new(Query, Mutation);
|
||||||
let context = Context {
|
let state = warp::any().map(move || Context {
|
||||||
databases: databases.into_iter().map(from_db).collect(),
|
databases: databases.clone().into_iter().map(from_db).collect(),
|
||||||
};
|
});
|
||||||
let data = std::sync::Arc::new(GQLData { schema, context });
|
let graphql_filter = juniper_warp::make_graphql_filter(schema, state.boxed());
|
||||||
|
|
||||||
// Start http server
|
warp::serve(
|
||||||
HttpServer::new(move || {
|
warp::get2()
|
||||||
App::new()
|
.and(warp::path("graphiql"))
|
||||||
.data(data.clone())
|
.and(juniper_warp::graphiql_filter("/graphql"))
|
||||||
.wrap(middleware::Logger::default())
|
.or(warp::path("graphql").and(graphql_filter)),
|
||||||
.wrap(
|
)
|
||||||
Cors::new()
|
.run(([127, 0, 0, 1], 8080));
|
||||||
.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
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,7 @@ use clap::{App, Arg};
|
||||||
use database::scan_dbs;
|
use database::scan_dbs;
|
||||||
use graphql::server;
|
use graphql::server;
|
||||||
|
|
||||||
#[actix_rt::main]
|
fn main() -> std::io::Result<()> {
|
||||||
async fn main() -> std::io::Result<()> {
|
|
||||||
let cmd = App::new("Riplog")
|
let cmd = App::new("Riplog")
|
||||||
.version("1.0")
|
.version("1.0")
|
||||||
.arg(
|
.arg(
|
||||||
|
@ -22,13 +21,14 @@ async 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:8080"),
|
.default_value("127.0.0.1:9743")
|
||||||
|
.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(addr, logs).await
|
server(logs);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
3
frontend/.gitignore
vendored
3
frontend/.gitignore
vendored
|
@ -1,3 +0,0 @@
|
||||||
node_modules
|
|
||||||
.cache
|
|
||||||
dist
|
|
Reference in a new issue