Rust reimplementation of Angry.Im
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.rs 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. extern crate actix;
  2. extern crate actix_web;
  3. extern crate bytes;
  4. extern crate byteorder;
  5. extern crate htmlescape;
  6. extern crate rand;
  7. extern crate futures;
  8. extern crate serde;
  9. #[macro_use]
  10. extern crate serde_derive;
  11. extern crate sled;
  12. extern crate tokio_threadpool;
  13. mod util;
  14. mod db_sync;
  15. #[macro_use]
  16. mod app;
  17. mod life;
  18. mod url;
  19. mod paste;
  20. use actix_web::{fs, http, server, App, Path, Result};
  21. use sled::{ConfigBuilder, Tree};
  22. fn main() {
  23. let actix_sys = actix::System::new("imangry");
  24. let db = open_db("data/db");
  25. let db_sync_addr = db_sync::DbSyncActor::start_actor(&db);
  26. let state = app::AngryAppState::new(db, db_sync_addr);
  27. server::new(move || {
  28. let mut app = App::with_state(state.clone())
  29. .route("/", http::Method::GET, index);
  30. app = life::setup_routes(app);
  31. app = url::setup_routes(app);
  32. app = paste::setup_routes(app);
  33. // The static interface
  34. app = app.handler("/",
  35. fs::StaticFiles::new("./static").unwrap());
  36. app
  37. }).bind("127.0.0.1:60324").unwrap().start();
  38. actix_sys.run();
  39. }
  40. fn index(_info: Path<()>) -> Result<fs::NamedFile> {
  41. Ok(fs::NamedFile::open("./static/index.html")?)
  42. }
  43. fn open_db(db_path: &str) -> Tree {
  44. let config = ConfigBuilder::new()
  45. .path(db_path.to_owned())
  46. .io_buf_size(65535)
  47. .min_items_per_segment(4) // For maximum 16k key/value pair
  48. .build();
  49. Tree::start(config).unwrap()
  50. }