+13
-1
@@ -10,10 +10,12 @@ use crate::providers::ollama::client::OllamaProvider;
|
||||
use crate::state::app_state::AppState;
|
||||
|
||||
use axum::Router;
|
||||
use axum::http::{HeaderValue, Method, header};
|
||||
use once_cell::sync::Lazy;
|
||||
use std::env;
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
use tower_http::cors::CorsLayer;
|
||||
|
||||
static OLLAMA_URL: Lazy<String> = Lazy::new(|| env::var("OLLAMA_URL").expect("OLLAMA_URL not set"));
|
||||
|
||||
@@ -28,11 +30,21 @@ async fn main() {
|
||||
ollama: Arc::new(OllamaProvider::new(OLLAMA_URL.as_str())),
|
||||
};
|
||||
|
||||
let cors_origin =
|
||||
env::var("CORS_ORIGIN").unwrap_or_else(|_| "http://localhost:3000".to_string());
|
||||
|
||||
let cors = CorsLayer::new()
|
||||
.allow_origin(cors_origin.parse::<HeaderValue>().unwrap())
|
||||
.allow_methods([Method::GET, Method::POST, Method::PUT, Method::DELETE])
|
||||
.allow_headers([header::CONTENT_TYPE, header::AUTHORIZATION, header::ACCEPT])
|
||||
.allow_credentials(true);
|
||||
|
||||
let app = Router::new()
|
||||
.nest("/v1", routes::v1::router())
|
||||
.layer(cors)
|
||||
.with_state(state);
|
||||
|
||||
let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
|
||||
let addr = SocketAddr::from(([0, 0, 0, 0], 3001));
|
||||
println!("Server running on {}", addr);
|
||||
|
||||
axum::serve(tokio::net::TcpListener::bind(addr).await.unwrap(), app)
|
||||
|
||||
Reference in New Issue
Block a user