mirror of
https://github.com/amigan/rustypaste-pretty.git
synced 2024-11-21 20:09:48 -05:00
refactor(server): define global constants for environment variables
This commit is contained in:
parent
c48e45d68c
commit
a3e266b8b4
3 changed files with 9 additions and 4 deletions
|
@ -27,3 +27,9 @@ pub mod mime;
|
||||||
|
|
||||||
/// Helper functions.
|
/// Helper functions.
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
||||||
|
/// Environment variable for setting the configuration file path.
|
||||||
|
pub const CONFIG_ENV: &str = "CONFIG";
|
||||||
|
|
||||||
|
/// Environment variable for setting the authentication token.
|
||||||
|
pub const AUTH_TOKEN_ENV: &str = "AUTH_TOKEN";
|
||||||
|
|
|
@ -6,6 +6,7 @@ use hotwatch::{Event, Hotwatch};
|
||||||
use rustypaste::config::Config;
|
use rustypaste::config::Config;
|
||||||
use rustypaste::paste::PasteType;
|
use rustypaste::paste::PasteType;
|
||||||
use rustypaste::server;
|
use rustypaste::server;
|
||||||
|
use rustypaste::CONFIG_ENV;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::Result as IoResult;
|
use std::io::Result as IoResult;
|
||||||
|
@ -13,9 +14,6 @@ use std::path::PathBuf;
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
/// Environment variable for setting the configuration file path.
|
|
||||||
const CONFIG_ENV: &str = "CONFIG";
|
|
||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> IoResult<()> {
|
async fn main() -> IoResult<()> {
|
||||||
// Initialize logger.
|
// Initialize logger.
|
||||||
|
|
|
@ -5,6 +5,7 @@ use crate::header::{self, ContentDisposition};
|
||||||
use crate::mime;
|
use crate::mime;
|
||||||
use crate::paste::{Paste, PasteType};
|
use crate::paste::{Paste, PasteType};
|
||||||
use crate::util;
|
use crate::util;
|
||||||
|
use crate::AUTH_TOKEN_ENV;
|
||||||
use actix_files::NamedFile;
|
use actix_files::NamedFile;
|
||||||
use actix_multipart::Multipart;
|
use actix_multipart::Multipart;
|
||||||
use actix_web::{error, get, post, web, Error, HttpRequest, HttpResponse, Responder};
|
use actix_web::{error, get, post, web, Error, HttpRequest, HttpResponse, Responder};
|
||||||
|
@ -94,7 +95,7 @@ async fn upload(
|
||||||
auth::check(
|
auth::check(
|
||||||
host,
|
host,
|
||||||
request.headers(),
|
request.headers(),
|
||||||
env::var("AUTH_TOKEN").ok().or(config
|
env::var(AUTH_TOKEN_ENV).ok().or(config
|
||||||
.read()
|
.read()
|
||||||
.map_err(|_| error::ErrorInternalServerError("cannot acquire config"))?
|
.map_err(|_| error::ErrorInternalServerError("cannot acquire config"))?
|
||||||
.server
|
.server
|
||||||
|
|
Loading…
Reference in a new issue