| 123456789101112131415161718192021222324252627282930313233 |
- use actix_web::{HttpServer, web, App};
- use actix_cors::Cors;
- #[actix_web::main]
- async fn main() -> std::io::Result<()> {
- let app_env = std::env::var("APP_ENV").unwrap_or_else(|_| "development".to_string());
- HttpServer::new(move || {
- let cors = if app_env == "development" {
- Cors::permissive()
- } else {
- Cors::default()
- .allowed_origin_fn(|origin, _req| {
- origin.as_bytes().ends_with(b".example.com")
- })
- .allowed_methods(vec!["GET", "POST", "PUT", "PATCH", "DELETE"])
- .allow_any_header()
- .supports_credentials()
- };
- App::new()
- .wrap(cors)
- .app_data(
- web::JsonConfig::default().error_handler(|err, _req| {
- AppError::JsonDeserializationError(err.to_string()).into()
- })
- )
- .configure(routes::other::config)
- })
- .bind(("0.0.0.0", 8000))?
- .run()
- .await
- }
|