Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit e5702b36 authored by peterrabbit's avatar peterrabbit
Browse files

ip serve static files

parent 2e57f968
No related branches found
No related tags found
No related merge requests found
......@@ -517,6 +517,7 @@ dependencies = [
name = "cms_rust"
version = "0.1.0"
dependencies = [
"actix-files",
"actix-web",
"actix-web-lab",
"dirs",
......
......@@ -17,3 +17,4 @@ dirs = "4.0"
structopt = "0.3"
env_logger = "0.9"
actix-web-lab = "0.17.0"
actix-files = "0.6.2"
default_static/favicon.ico

7.58 KiB

use crate::app::AppArgs;
use std::path::PathBuf;
use structopt::StructOpt;
#[derive(Clone)]
pub enum AppContext {
......@@ -22,8 +21,7 @@ pub struct AppConfig {
}
impl AppConfig {
pub fn new() -> Self {
let app_args = AppArgs::from_args();
pub fn new(app_args: AppArgs) -> Self {
let exec_path = std::env::current_exe().unwrap();
let exec_name = exec_path
.file_name()
......
use crate::app::{AppConfig, AppPreferences};
use crate::app::{AppArgs, AppConfig, AppPreferences};
use structopt::StructOpt;
#[derive(Clone)]
pub struct AppState {
......@@ -11,7 +12,7 @@ pub struct AppState {
impl AppState {
pub fn new() -> Self {
AppState {
config: AppConfig::new(),
config: AppConfig::new(AppArgs::from_args()),
preferences: AppPreferences {},
}
}
......
......@@ -4,6 +4,7 @@ mod static_files;
mod testing;
mod tls_config;
mod website;
use actix_files::Files;
use actix_web::{App, HttpServer};
use actix_web_lab::middleware::RedirectHttps;
use app::AppState;
......@@ -29,8 +30,8 @@ async fn main() -> std::io::Result<()> {
let port_tls = app_state.config.port_tls;
let srv_conf = tls_config(&app_state.config);
let static_files_manager =
let static_dir = static_files_manager.dir.clone();
let mut_static_files_manager =
actix_web::web::Data::new(std::sync::Mutex::new(static_files_manager));
let app_state = actix_web::web::Data::new(std::sync::Mutex::new(app_state));
......@@ -41,8 +42,10 @@ async fn main() -> std::io::Result<()> {
.wrap(actix_web::middleware::Compress::default())
.wrap(RedirectHttps::default().to_port(port_tls))
.app_data(actix_web::web::Data::clone(&app_state))
.app_data(actix_web::web::Data::clone(&static_files_manager))
.app_data(actix_web::web::Data::clone(&mut_static_files_manager))
.app_data(actix_web::web::Data::new(website.clone()))
.service(Files::new("/static/", &static_dir))
.service(service::files::favicon)
.service(service::page)
})
.bind(format!("{}:{}", host, port))?
......
use crate::static_files::StaticFilesManager;
use actix_files::NamedFile;
use actix_web::{get, web, Responder};
#[get("/favicon.ico")]
pub async fn favicon(
static_files_manager: web::Data<std::sync::Mutex<StaticFilesManager>>,
) -> impl Responder {
let static_files_manager = static_files_manager.lock().unwrap();
NamedFile::open(static_files_manager.dir.join("default").join("favicon.ico"))
}
pub mod files;
mod page;
pub use page::*;
use crate::app::AppState;
use std::path::{Path, PathBuf};
#[derive(Clone)]
pub struct StaticFilesManager {
dir: PathBuf,
index: Vec<String>,
pub dir: PathBuf,
pub index: Vec<String>,
}
impl StaticFilesManager {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment