gbserver/src/main.rs

74 lines
2.2 KiB
Rust
Raw Normal View History

2025-07-04 10:39:31 -03:00
use actix_cors::Cors;
use actix_web::http::header;
use actix_web::{web, App, HttpServer};
use dotenv::dotenv;
2025-07-04 23:20:48 -03:00
use services::config::*;
use services::email::*;
use services::file::*;
2025-07-04 23:20:48 -03:00
use services::llm::*;
2025-07-19 12:10:16 -03:00
use services::script::*;
use services::state::*;
use sqlx::PgPool;
//use services:: find::*;
mod services;
#[tokio::main(flavor = "multi_thread")]
async fn main() -> std::io::Result<()> {
dotenv().ok();
let config = AppConfig::from_env();
let db_url = config.database_url();
let db_custom_url = config.database_custom_url();
let db = PgPool::connect(&db_url).await.unwrap();
let db_custom = PgPool::connect(&db_custom_url).await.unwrap();
let minio_client = init_minio(&config)
.await
.expect("Failed to initialize Minio");
let app_state = web::Data::new(AppState {
db: db.into(),
db_custom: db_custom.into(),
config: Some(config.clone()),
minio_client: minio_client.into(),
});
2025-07-19 12:10:16 -03:00
let script_service = ScriptService::new(&app_state.clone());
const TEXT : &str = include_str!("prompts/business/data-enrichment.bas");
match script_service.compile(TEXT) {
Ok(ast) => match script_service.run(&ast) {
Ok(result) => println!("Script executed successfully: {:?}", result),
Err(e) => eprintln!("Error executing script: {}", e),
},
Err(e) => eprintln!("Error compiling script: {}", e),
}
// Start HTTP server
HttpServer::new(move || {
2025-07-04 10:39:31 -03:00
let cors = Cors::default()
2025-07-19 12:10:16 -03:00
.send_wildcard()
.allowed_origin("*")
2025-07-04 10:39:31 -03:00
.allowed_methods(vec!["GET", "POST", "PUT", "DELETE"])
.allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT])
.allowed_header(header::CONTENT_TYPE)
.max_age(3600);
App::new()
2025-07-19 12:10:16 -03:00
.wrap(cors)
.app_data(app_state.clone())
.service(upload_file)
.service(list_file)
.service(save_click)
.service(get_emails)
2025-07-04 10:39:31 -03:00
.service(list_emails)
.service(send_email)
2025-07-04 23:20:48 -03:00
.service(chat_stream)
.service(chat)
})
.bind((config.server.host.clone(), config.server.port))?
.run()
.await
}