Skip to content

Commit

Permalink
Merge pull request #16 from brecert/project-consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
insertish committed Sep 24, 2021
2 parents 82fc3a1 + 2836a43 commit 695fc97
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 2 deletions.
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.");
}

0 comments on commit 695fc97

Please sign in to comment.