Add docker build to main. (#16)
Reviewed-on: #16 Co-authored-by: Drew Galbraith <drew@tiramisu.one> Co-committed-by: Drew Galbraith <drew@tiramisu.one>
This commit is contained in:
parent
ff6837a751
commit
25eb4af14d
10 changed files with 205 additions and 24 deletions
|
|
@ -1,4 +1,5 @@
|
|||
use axum::{Router, routing::get};
|
||||
use tower_http::cors::{Any, CorsLayer};
|
||||
|
||||
mod database;
|
||||
mod models;
|
||||
|
|
@ -13,13 +14,33 @@ async fn main() {
|
|||
let pool = database::create_pool(&binding)
|
||||
.await
|
||||
.expect("Failed to create database pool");
|
||||
let cors = if std::env::var("RUST_ENV").unwrap_or_default() == "production" {
|
||||
CorsLayer::new()
|
||||
.allow_origin([
|
||||
"https://tiramisu.one"
|
||||
.parse::<axum::http::HeaderValue>()
|
||||
.unwrap(),
|
||||
"https://*.tiramisu.one"
|
||||
.parse::<axum::http::HeaderValue>()
|
||||
.unwrap(),
|
||||
])
|
||||
.allow_methods(Any)
|
||||
.allow_headers(Any)
|
||||
} else {
|
||||
CorsLayer::new()
|
||||
.allow_origin(Any)
|
||||
.allow_methods(Any)
|
||||
.allow_headers(Any)
|
||||
};
|
||||
|
||||
let app = Router::new()
|
||||
.route("/health", get(health))
|
||||
.nest("/api/tasks", services::create_task_router())
|
||||
.layer(cors)
|
||||
.with_state(pool);
|
||||
|
||||
let port = std::env::var("PORT").unwrap_or("3000".to_string());
|
||||
let addr = format!("127.0.0.1:{}", port);
|
||||
let addr = format!("0.0.0.0:{}", port);
|
||||
|
||||
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue