2021-07-19 18:35:52 -04:00
|
|
|
use actix_web::middleware::Logger;
|
2021-07-23 15:52:00 -04:00
|
|
|
use actix_web::{App, HttpServer};
|
2021-07-24 13:46:22 -04:00
|
|
|
use rustypaste::config::Config;
|
2021-08-26 14:09:33 -04:00
|
|
|
use rustypaste::paste::PasteType;
|
2021-07-24 13:46:22 -04:00
|
|
|
use rustypaste::server;
|
2021-07-24 13:51:08 -04:00
|
|
|
use std::env;
|
2021-07-23 15:52:00 -04:00
|
|
|
use std::fs;
|
|
|
|
use std::io::Result as IoResult;
|
2021-07-19 18:35:52 -04:00
|
|
|
|
|
|
|
#[actix_web::main]
|
2021-07-23 15:52:00 -04:00
|
|
|
async fn main() -> IoResult<()> {
|
2021-07-24 07:10:30 -04:00
|
|
|
dotenv::dotenv().ok();
|
2021-07-19 18:35:52 -04:00
|
|
|
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
2021-07-24 13:51:08 -04:00
|
|
|
let config = Config::parse(env::var("CONFIG").as_deref().unwrap_or("config"))
|
|
|
|
.expect("failed to parse config");
|
2021-07-23 15:52:00 -04:00
|
|
|
let server_config = config.server.clone();
|
2021-08-04 10:35:54 -04:00
|
|
|
fs::create_dir_all(&server_config.upload_path)?;
|
2021-08-27 09:05:40 -04:00
|
|
|
for paste_type in &[PasteType::Url, PasteType::Oneshot] {
|
2021-08-26 15:57:46 -04:00
|
|
|
fs::create_dir_all(paste_type.get_path(&server_config.upload_path))?;
|
|
|
|
}
|
2021-07-23 15:52:00 -04:00
|
|
|
let mut http_server = HttpServer::new(move || {
|
|
|
|
App::new()
|
|
|
|
.data(config.clone())
|
|
|
|
.wrap(Logger::default())
|
|
|
|
.configure(server::configure_routes)
|
|
|
|
})
|
|
|
|
.bind(server_config.address)?;
|
|
|
|
if let Some(workers) = server_config.workers {
|
|
|
|
http_server = http_server.workers(workers);
|
|
|
|
}
|
|
|
|
http_server.run().await
|
2021-07-19 15:16:13 -04:00
|
|
|
}
|