database support
This commit is contained in:
39
src/main.rs
39
src/main.rs
@@ -1,26 +1,53 @@
|
||||
#![allow(non_snake_case)]
|
||||
#[macro_use]
|
||||
extern crate diesel;
|
||||
|
||||
use diesel::{r2d2::{self, ConnectionManager}, SqliteConnection};
|
||||
use dotenvy::dotenv;
|
||||
use ntex_files as fs;
|
||||
use ntex::web;
|
||||
mod api;
|
||||
mod status;
|
||||
mod videos;
|
||||
mod providers;
|
||||
mod util;
|
||||
|
||||
mod api;
|
||||
mod db;
|
||||
mod models;
|
||||
mod providers;
|
||||
mod schema;
|
||||
mod status;
|
||||
mod util;
|
||||
mod videos;
|
||||
|
||||
type DbPool = r2d2::Pool<ConnectionManager<SqliteConnection>>;
|
||||
|
||||
#[ntex::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
std::env::set_var("RUST_BACKTRACE", "1");
|
||||
env_logger::init(); // You need this to actually see logs
|
||||
dotenv().ok();
|
||||
|
||||
// set up database connection pool
|
||||
let connspec = std::env::var("DATABASE_URL").expect("DATABASE_URL");
|
||||
let manager = ConnectionManager::<SqliteConnection>::new(connspec);
|
||||
let pool = r2d2::Pool::builder()
|
||||
.build(manager)
|
||||
.expect("Failed to create pool.");
|
||||
|
||||
let cache: util::cache::VideoCache = crate::util::cache::VideoCache::new();
|
||||
|
||||
web::HttpServer::new(move || {
|
||||
web::App::new()
|
||||
.state(pool.clone())
|
||||
.state(cache.clone())
|
||||
.wrap(web::middleware::Logger::default())
|
||||
.service(web::scope("/api").configure(api::config))
|
||||
.service(fs::Files::new("/", "static"))
|
||||
.service(
|
||||
web::resource("/")
|
||||
.route(web::get().to(|| async {
|
||||
web::HttpResponse::Found()
|
||||
.header("Location", "hottub://source?url=hottub.spacemoehre.de")
|
||||
.finish()
|
||||
}))
|
||||
)
|
||||
.service(fs::Files::new("/", "static").index_file("index.html"))
|
||||
})
|
||||
// .bind_openssl(("0.0.0.0", 18080), builder)?
|
||||
.bind(("0.0.0.0", 18080))?
|
||||
|
||||
Reference in New Issue
Block a user