IS THIS DONE YET?
This commit is contained in:
parent
ab603643c9
commit
a572ca0d7c
5 changed files with 795 additions and 855 deletions
1554
Cargo.lock
generated
1554
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -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"
|
||||||
|
|
|
@ -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,20 +252,52 @@ impl Mutation {}
|
||||||
|
|
||||||
type Schema = juniper::RootNode<'static, Query, Mutation>;
|
type Schema = juniper::RootNode<'static, Query, Mutation>;
|
||||||
|
|
||||||
pub fn server(bind: &str, port: u16, 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)?)
|
||||||
println!("Starting server at {}:{}\n\nEndpoints:\n graphql: http://{}:{}/graphql\n graphiql: http://{}:{}/graphiql", bind, port, bind, port, bind, port);
|
})
|
||||||
|
.await?;
|
||||||
warp::serve(
|
Ok(HttpResponse::Ok()
|
||||||
warp::get2()
|
.content_type("application/json")
|
||||||
.and(warp::path("graphiql"))
|
.body(user))
|
||||||
.and(juniper_warp::graphiql_filter("/graphql"))
|
}
|
||||||
.or(warp::path("graphql").and(graphql_filter)),
|
|
||||||
)
|
struct GQLData {
|
||||||
.run(std::net::SocketAddr::new(bind.parse().unwrap(), port));
|
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,22 +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"),
|
.default_value("127.0.0.1:8080"),
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("port")
|
|
||||||
.required(true)
|
|
||||||
.short("p")
|
|
||||||
.help("Port to listen on")
|
|
||||||
.default_value("8080"),
|
|
||||||
)
|
)
|
||||||
.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 addr = cmd.value_of("bind").unwrap();
|
||||||
let port = cmd.value_of("port").unwrap().parse().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, port, logs);
|
server(addr, logs).await
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
3
frontend/.gitignore
vendored
Normal file
3
frontend/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
node_modules
|
||||||
|
.cache
|
||||||
|
dist
|
Reference in a new issue