GeneIT/geneit_backend/src/main.rs

130 lines
4.6 KiB
Rust
Raw Normal View History

2023-06-06 13:47:30 +00:00
use actix_cors::Cors;
2023-05-24 14:19:46 +00:00
use actix_remote_ip::RemoteIPConfig;
use actix_web::middleware::Logger;
2023-05-24 12:38:18 +00:00
use actix_web::{web, App, HttpServer};
use geneit_backend::app_config::AppConfig;
2023-06-16 15:51:51 +00:00
use geneit_backend::controllers::{
auth_controller, families_controller, server_controller, users_controller,
};
2023-05-24 12:38:18 +00:00
#[actix_web::main]
async fn main() -> std::io::Result<()> {
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
log::info!("Start to listen on {}", AppConfig::get().listen_address);
HttpServer::new(|| {
App::new()
2023-06-06 13:47:30 +00:00
.wrap(
Cors::default()
.allowed_origin(&AppConfig::get().website_origin)
.allowed_methods(vec!["GET", "POST"])
.allowed_header("X-Auth-Token")
2023-06-09 08:45:01 +00:00
.allow_any_header()
2023-06-06 13:47:30 +00:00
.supports_credentials()
.max_age(3600),
)
2023-05-24 14:19:46 +00:00
.wrap(Logger::default())
.app_data(web::Data::new(RemoteIPConfig {
proxy: AppConfig::get().proxy_ip.clone(),
}))
2023-05-24 12:38:18 +00:00
// Config controller
.route("/", web::get().to(server_controller::home))
2023-05-24 12:38:18 +00:00
.route(
"/server/config",
web::get().to(server_controller::server_config),
2023-05-24 12:38:18 +00:00
)
2023-05-24 14:19:46 +00:00
// Auth controller
.route(
"/auth/create_account",
web::post().to(auth_controller::create_account),
)
2023-05-31 11:56:18 +00:00
.route(
"/auth/request_reset_password",
web::post().to(auth_controller::request_reset_password),
)
.route(
"/auth/check_reset_password_token",
web::post().to(auth_controller::check_reset_password_token),
)
2023-05-31 11:33:26 +00:00
.route(
"/auth/reset_password",
web::post().to(auth_controller::reset_password),
)
2023-05-31 13:17:00 +00:00
.route(
"/auth/password_login",
web::post().to(auth_controller::password_login),
)
2023-06-02 09:49:18 +00:00
.route(
"/auth/start_openid_login",
web::post().to(auth_controller::start_openid_login),
)
2023-06-02 13:04:49 +00:00
.route(
"/auth/finish_openid_login",
web::post().to(auth_controller::finish_openid_login),
)
2023-06-02 13:35:07 +00:00
.route("/auth/logout", web::get().to(auth_controller::logout))
2023-05-31 13:52:49 +00:00
// User controller
2023-06-16 15:51:51 +00:00
.route("/user/info", web::get().to(users_controller::auth_info))
2023-06-05 16:52:00 +00:00
.route(
"/user/update_profile",
2023-06-16 15:51:51 +00:00
web::post().to(users_controller::update_profile),
2023-06-05 16:52:00 +00:00
)
2023-06-05 17:02:51 +00:00
.route(
"/user/replace_password",
2023-06-16 15:51:51 +00:00
web::post().to(users_controller::replace_password),
2023-06-05 17:02:51 +00:00
)
2023-06-06 07:47:52 +00:00
.route(
"/user/request_delete",
2023-06-16 15:51:51 +00:00
web::get().to(users_controller::request_delete_account),
2023-06-06 07:47:52 +00:00
)
2023-06-06 08:02:41 +00:00
.route(
"/user/check_delete_token",
2023-06-16 15:51:51 +00:00
web::post().to(users_controller::check_delete_token),
2023-06-06 08:02:41 +00:00
)
2023-06-06 08:19:54 +00:00
.route(
"/user/delete_account",
2023-06-16 15:51:51 +00:00
web::post().to(users_controller::delete_account),
)
// Families controller
.route(
"/family/create",
web::post().to(families_controller::create),
2023-06-06 08:19:54 +00:00
)
2023-06-17 16:55:07 +00:00
.route("/family/join", web::post().to(families_controller::join))
2023-06-20 16:55:14 +00:00
.route("/family/list", web::get().to(families_controller::list))
2023-06-21 14:36:46 +00:00
.route(
2023-06-21 16:15:20 +00:00
"/family/{id}",
2023-06-21 14:36:46 +00:00
web::get().to(families_controller::single_info),
)
2023-06-21 15:35:07 +00:00
.route(
"/family/{id}/leave",
web::post().to(families_controller::leave),
)
2023-06-22 12:37:48 +00:00
.route("/family/{id}", web::patch().to(families_controller::update))
2023-06-21 16:15:20 +00:00
.route(
"/family/{id}",
web::delete().to(families_controller::delete),
)
.route(
"/family/{id}/renew_invitation_code",
web::post().to(families_controller::renew_invitation_code),
)
2023-06-21 15:01:52 +00:00
.route(
"/family/{id}/users",
web::get().to(families_controller::users),
)
2023-06-22 14:03:11 +00:00
.route(
"/family/{id}/user/{user_id}",
web::patch().to(families_controller::update_membership),
)
.route(
"/family/{id}/user/{user_id}",
web::delete().to(families_controller::delete_membership),
)
2023-05-24 12:38:18 +00:00
})
.bind(AppConfig::get().listen_address.as_str())?
.run()
.await
2023-05-24 09:37:02 +00:00
}