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"
|
||||
walkdir = "2"
|
||||
juniper = "0.14"
|
||||
juniper_warp = "0.5.2"
|
||||
warp = "0.1.8"
|
||||
serde = "1.0.103"
|
||||
serde_json = "1.0.44"
|
||||
actix-web = "2.0.0"
|
||||
actix-rt = "1.0.0"
|
||||
actix-cors = "0.2.0"
|
||||
|
||||
[dependencies.rusqlite]
|
||||
version = "0.21.0"
|
||||
|
|
|
@ -2,11 +2,15 @@ extern crate juniper;
|
|||
|
||||
use crate::database::{DBLog, DBMessage};
|
||||
use chrono::prelude::*;
|
||||
use juniper::http::GraphQLRequest;
|
||||
use juniper::Value::Null;
|
||||
use juniper::{FieldError, FieldResult};
|
||||
use std::collections::HashSet;
|
||||
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)]
|
||||
#[graphql(description = "Paginated list of messages")]
|
||||
|
@ -248,20 +252,52 @@ impl Mutation {}
|
|||
|
||||
type Schema = juniper::RootNode<'static, Query, Mutation>;
|
||||
|
||||
pub fn server(bind: &str, port: u16, databases: Vec<DBLog>) {
|
||||
let schema = Schema::new(Query, Mutation);
|
||||
let state = warp::any().map(move || Context {
|
||||
databases: databases.clone().into_iter().map(from_db).collect(),
|
||||
});
|
||||
let graphql_filter = juniper_warp::make_graphql_filter(schema, state.boxed());
|
||||
|
||||
println!("Starting server at {}:{}\n\nEndpoints:\n graphql: http://{}:{}/graphql\n graphiql: http://{}:{}/graphiql", bind, port, bind, port, bind, port);
|
||||
|
||||
warp::serve(
|
||||
warp::get2()
|
||||
.and(warp::path("graphiql"))
|
||||
.and(juniper_warp::graphiql_filter("/graphql"))
|
||||
.or(warp::path("graphql").and(graphql_filter)),
|
||||
)
|
||||
.run(std::net::SocketAddr::new(bind.parse().unwrap(), port));
|
||||
async fn graphql(
|
||||
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 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 graphql::server;
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
#[actix_rt::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
let cmd = App::new("Riplog")
|
||||
.version("1.0")
|
||||
.arg(
|
||||
|
@ -21,22 +22,13 @@ fn main() -> std::io::Result<()> {
|
|||
.required(true)
|
||||
.short("b")
|
||||
.help("Address to bind to")
|
||||
.default_value("127.0.0.1"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("port")
|
||||
.required(true)
|
||||
.short("p")
|
||||
.help("Port to listen on")
|
||||
.default_value("8080"),
|
||||
.default_value("127.0.0.1:8080"),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let basedir = cmd.value_of("basedir").unwrap();
|
||||
let addr = cmd.value_of("bind").unwrap();
|
||||
let port = cmd.value_of("port").unwrap().parse().unwrap();
|
||||
let logs = scan_dbs(basedir);
|
||||
println!("Loaded data for {} workspaces", logs.len());
|
||||
server(addr, port, logs);
|
||||
Ok(())
|
||||
server(addr, logs).await
|
||||
}
|
||||
|
|
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