Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve project consistency #16

Merged
merged 3 commits into from Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 50 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Expand Up @@ -14,4 +14,6 @@ scraper = "0.12.0"
serde_json = "1"
mime = "0.3.16"
serde = "1"
regex = "1"
regex = "1"
log = "0.4.14"
env_logger = "0.8.4"
1 change: 1 addition & 0 deletions Dockerfile
Expand Up @@ -13,4 +13,5 @@ FROM alpine:latest
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
COPY --from=builder /home/rust/src/january/target/x86_64-unknown-linux-musl/release/january ./
EXPOSE 7000
ENV JANUARY_HOST 0.0.0.0:7000
CMD ["./january"]
11 changes: 10 additions & 1 deletion src/main.rs
@@ -1,20 +1,29 @@
#[macro_use]
extern crate lazy_static;

use actix_web::middleware::Logger;
use actix_web::{web, App, HttpServer};
use log::info;
use util::variables::HOST;

pub mod routes;
pub mod structs;
pub mod util;

#[actix_web::main]
async fn main() -> std::io::Result<()> {
env_logger::init_from_env(env_logger::Env::default().filter_or("RUST_LOG", "info"));

info!("Starting January server.");

HttpServer::new(|| {
App::new()
.wrap(Logger::default())
.route("/", web::get().to(routes::info::get))
.route("/embed", web::get().to(routes::embed::get))
.route("/proxy", web::get().to(routes::proxy::get))
})
.bind(("0.0.0.0", 7000))?
.bind(HOST.clone())?
.run()
.await
}
14 changes: 14 additions & 0 deletions src/routes/info.rs
@@ -0,0 +1,14 @@
use actix_web::web;
use actix_web::Responder;
use serde::Serialize;

#[derive(Debug, Serialize)]
pub struct Info {
january: &'static str,
}

pub async fn get() -> impl Responder {
web::Json(Info {
january: env!("CARGO_PKG_VERSION"),
})
}
1 change: 1 addition & 0 deletions src/routes/mod.rs
@@ -1,2 +1,3 @@
pub mod embed;
pub mod proxy;
pub mod info;
1 change: 1 addition & 0 deletions src/util/mod.rs
@@ -1,2 +1,3 @@
pub mod request;
pub mod result;
pub mod variables;
7 changes: 7 additions & 0 deletions src/util/variables.rs
@@ -0,0 +1,7 @@
use std::env;

lazy_static! {
// Application Settings
pub static ref HOST: String =
env::var("JANUARY_HOST").expect("Missing JANUARY_HOST environment variable.");
}