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::sync::Arc;
|
||||
|
||||
mod api;
|
||||
#[cfg(test)]
|
||||
mod api_tests;
|
||||
mod config;
|
||||
mod db;
|
||||
mod ddns;
|
||||
|
@ -38,17 +35,13 @@ mod index;
|
|||
mod lastfm;
|
||||
mod metadata;
|
||||
mod playlist;
|
||||
mod serve;
|
||||
mod server;
|
||||
mod swagger;
|
||||
#[cfg(test)]
|
||||
mod test;
|
||||
mod service;
|
||||
|
||||
mod thumbnails;
|
||||
mod ui;
|
||||
mod user;
|
||||
mod utils;
|
||||
mod vfs;
|
||||
mod web;
|
||||
|
||||
fn log_config() -> simplelog::Config {
|
||||
simplelog::ConfigBuilder::new()
|
||||
|
@ -227,7 +220,7 @@ fn main() -> Result<()> {
|
|||
.parse()
|
||||
.with_context(|| "Invalid port number")?;
|
||||
|
||||
let server = server::get_server(
|
||||
let server = service::server::get_server(
|
||||
port,
|
||||
Some(auth_secret.as_slice()),
|
||||
&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 time::Duration;
|
||||
|
||||
use super::serve;
|
||||
use crate::config::{self, Config, Preferences};
|
||||
use crate::db::DB;
|
||||
use crate::index;
|
||||
use crate::lastfm;
|
||||
use crate::playlist;
|
||||
use crate::serve;
|
||||
use crate::thumbnails;
|
||||
use crate::user;
|
||||
use crate::utils;
|
|
@ -4,13 +4,13 @@ use rocket::http::Status;
|
|||
use rocket::local::Client;
|
||||
use std::{thread, time};
|
||||
|
||||
use crate::api;
|
||||
use super::api;
|
||||
use crate::config;
|
||||
use crate::ddns;
|
||||
use crate::index;
|
||||
use crate::vfs;
|
||||
|
||||
use crate::test::get_test_environment;
|
||||
use super::test::get_test_environment;
|
||||
|
||||
const TEST_USERNAME: &str = "test_user";
|
||||
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::sync::Arc;
|
||||
|
||||
use super::api;
|
||||
use crate::db::DB;
|
||||
use crate::index::CommandSender;
|
||||
|
||||
|
@ -36,7 +37,7 @@ pub fn get_server(
|
|||
Ok(rocket::custom(config)
|
||||
.manage(db)
|
||||
.manage(command_sender)
|
||||
.mount(&api_url, crate::api::get_routes())
|
||||
.mount(&api_url, api::get_routes())
|
||||
.mount(
|
||||
&swagger_url,
|
||||
StaticFiles::from(swagger_dir_path).rank(swagger_routes_rank),
|
|
@ -1,6 +1,7 @@
|
|||
use super::test::get_test_environment;
|
||||
|
||||
#[test]
|
||||
fn test_index() {
|
||||
use crate::test::get_test_environment;
|
||||
use rocket::http::Status;
|
||||
let env = get_test_environment("swagger_index.sqlite");
|
||||
let client = &env.client;
|
||||
|
@ -10,7 +11,6 @@ fn test_index() {
|
|||
|
||||
#[test]
|
||||
fn test_index_with_trailing_slash() {
|
||||
use crate::test::get_test_environment;
|
||||
use rocket::http::Status;
|
||||
let env = get_test_environment("swagger_index_with_trailing_slash.sqlite");
|
||||
let client = &env.client;
|
|
@ -5,9 +5,9 @@ use std::ops::Deref;
|
|||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::server;
|
||||
use crate::db::DB;
|
||||
use crate::index;
|
||||
use crate::server;
|
||||
|
||||
pub struct TestEnvironment {
|
||||
pub client: Client,
|
|
@ -1,8 +1,8 @@
|
|||
use super::test::get_test_environment;
|
||||
use rocket::http::Status;
|
||||
|
||||
#[test]
|
||||
fn test_index() {
|
||||
use crate::test::get_test_environment;
|
||||
use rocket::http::Status;
|
||||
|
||||
let env = get_test_environment("web_index.sqlite");
|
||||
let client = &env.client;
|
||||
let response = client.get("/").dispatch();
|
Loading…
Add table
Reference in a new issue