Moved rocket stuff into its own module
This commit is contained in:
parent
fd8a6c64f5
commit
60f2e330a4
10 changed files with 30 additions and 20 deletions
13
src/main.rs
13
src/main.rs
|
@ -28,9 +28,6 @@ use simplelog::{LevelFilter, SimpleLogger, TermLogger, TerminalMode};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
mod api;
|
|
||||||
#[cfg(test)]
|
|
||||||
mod api_tests;
|
|
||||||
mod config;
|
mod config;
|
||||||
mod db;
|
mod db;
|
||||||
mod ddns;
|
mod ddns;
|
||||||
|
@ -38,17 +35,13 @@ mod index;
|
||||||
mod lastfm;
|
mod lastfm;
|
||||||
mod metadata;
|
mod metadata;
|
||||||
mod playlist;
|
mod playlist;
|
||||||
mod serve;
|
mod service;
|
||||||
mod server;
|
|
||||||
mod swagger;
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test;
|
|
||||||
mod thumbnails;
|
mod thumbnails;
|
||||||
mod ui;
|
mod ui;
|
||||||
mod user;
|
mod user;
|
||||||
mod utils;
|
mod utils;
|
||||||
mod vfs;
|
mod vfs;
|
||||||
mod web;
|
|
||||||
|
|
||||||
fn log_config() -> simplelog::Config {
|
fn log_config() -> simplelog::Config {
|
||||||
simplelog::ConfigBuilder::new()
|
simplelog::ConfigBuilder::new()
|
||||||
|
@ -227,7 +220,7 @@ fn main() -> Result<()> {
|
||||||
.parse()
|
.parse()
|
||||||
.with_context(|| "Invalid port number")?;
|
.with_context(|| "Invalid port number")?;
|
||||||
|
|
||||||
let server = server::get_server(
|
let server = service::server::get_server(
|
||||||
port,
|
port,
|
||||||
Some(auth_secret.as_slice()),
|
Some(auth_secret.as_slice()),
|
||||||
&api_url,
|
&api_url,
|
||||||
|
|
3
src/service/mod.rs
Normal file
3
src/service/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
mod rocket;
|
||||||
|
|
||||||
|
pub use self::rocket::*;
|
|
@ -14,12 +14,12 @@ use std::sync::Arc;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use time::Duration;
|
use time::Duration;
|
||||||
|
|
||||||
|
use super::serve;
|
||||||
use crate::config::{self, Config, Preferences};
|
use crate::config::{self, Config, Preferences};
|
||||||
use crate::db::DB;
|
use crate::db::DB;
|
||||||
use crate::index;
|
use crate::index;
|
||||||
use crate::lastfm;
|
use crate::lastfm;
|
||||||
use crate::playlist;
|
use crate::playlist;
|
||||||
use crate::serve;
|
|
||||||
use crate::thumbnails;
|
use crate::thumbnails;
|
||||||
use crate::user;
|
use crate::user;
|
||||||
use crate::utils;
|
use crate::utils;
|
|
@ -4,13 +4,13 @@ use rocket::http::Status;
|
||||||
use rocket::local::Client;
|
use rocket::local::Client;
|
||||||
use std::{thread, time};
|
use std::{thread, time};
|
||||||
|
|
||||||
use crate::api;
|
use super::api;
|
||||||
use crate::config;
|
use crate::config;
|
||||||
use crate::ddns;
|
use crate::ddns;
|
||||||
use crate::index;
|
use crate::index;
|
||||||
use crate::vfs;
|
use crate::vfs;
|
||||||
|
|
||||||
use crate::test::get_test_environment;
|
use super::test::get_test_environment;
|
||||||
|
|
||||||
const TEST_USERNAME: &str = "test_user";
|
const TEST_USERNAME: &str = "test_user";
|
||||||
const TEST_PASSWORD: &str = "test_password";
|
const TEST_PASSWORD: &str = "test_password";
|
13
src/service/rocket/mod.rs
Normal file
13
src/service/rocket/mod.rs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
mod api;
|
||||||
|
mod serve;
|
||||||
|
|
||||||
|
pub mod server;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod api_tests;
|
||||||
|
#[cfg(test)]
|
||||||
|
mod swagger;
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test;
|
||||||
|
#[cfg(test)]
|
||||||
|
mod web;
|
|
@ -5,6 +5,7 @@ use rocket_contrib::serve::StaticFiles;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use super::api;
|
||||||
use crate::db::DB;
|
use crate::db::DB;
|
||||||
use crate::index::CommandSender;
|
use crate::index::CommandSender;
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ pub fn get_server(
|
||||||
Ok(rocket::custom(config)
|
Ok(rocket::custom(config)
|
||||||
.manage(db)
|
.manage(db)
|
||||||
.manage(command_sender)
|
.manage(command_sender)
|
||||||
.mount(&api_url, crate::api::get_routes())
|
.mount(&api_url, api::get_routes())
|
||||||
.mount(
|
.mount(
|
||||||
&swagger_url,
|
&swagger_url,
|
||||||
StaticFiles::from(swagger_dir_path).rank(swagger_routes_rank),
|
StaticFiles::from(swagger_dir_path).rank(swagger_routes_rank),
|
|
@ -1,6 +1,7 @@
|
||||||
|
use super::test::get_test_environment;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_index() {
|
fn test_index() {
|
||||||
use crate::test::get_test_environment;
|
|
||||||
use rocket::http::Status;
|
use rocket::http::Status;
|
||||||
let env = get_test_environment("swagger_index.sqlite");
|
let env = get_test_environment("swagger_index.sqlite");
|
||||||
let client = &env.client;
|
let client = &env.client;
|
||||||
|
@ -10,7 +11,6 @@ fn test_index() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_index_with_trailing_slash() {
|
fn test_index_with_trailing_slash() {
|
||||||
use crate::test::get_test_environment;
|
|
||||||
use rocket::http::Status;
|
use rocket::http::Status;
|
||||||
let env = get_test_environment("swagger_index_with_trailing_slash.sqlite");
|
let env = get_test_environment("swagger_index_with_trailing_slash.sqlite");
|
||||||
let client = &env.client;
|
let client = &env.client;
|
|
@ -5,9 +5,9 @@ use std::ops::Deref;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use super::server;
|
||||||
use crate::db::DB;
|
use crate::db::DB;
|
||||||
use crate::index;
|
use crate::index;
|
||||||
use crate::server;
|
|
||||||
|
|
||||||
pub struct TestEnvironment {
|
pub struct TestEnvironment {
|
||||||
pub client: Client,
|
pub client: Client,
|
|
@ -1,8 +1,8 @@
|
||||||
|
use super::test::get_test_environment;
|
||||||
|
use rocket::http::Status;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_index() {
|
fn test_index() {
|
||||||
use crate::test::get_test_environment;
|
|
||||||
use rocket::http::Status;
|
|
||||||
|
|
||||||
let env = get_test_environment("web_index.sqlite");
|
let env = get_test_environment("web_index.sqlite");
|
||||||
let client = &env.client;
|
let client = &env.client;
|
||||||
let response = client.get("/").dispatch();
|
let response = client.get("/").dispatch();
|
Loading…
Add table
Reference in a new issue