GeneIT/geneit_backend/src/main.rs

91 lines
3.2 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;
use geneit_backend::controllers::{auth_controller, server_controller, user_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")
.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
.route("/user/info", web::get().to(user_controller::auth_info))
2023-06-05 16:52:00 +00:00
.route(
"/user/update_profile",
web::post().to(user_controller::update_profile),
)
2023-06-05 17:02:51 +00:00
.route(
"/user/replace_password",
web::post().to(user_controller::replace_password),
)
2023-06-06 07:47:52 +00:00
.route(
"/user/request_delete",
web::get().to(user_controller::request_delete_account),
)
2023-06-06 08:02:41 +00:00
.route(
"/user/check_delete_token",
web::post().to(user_controller::check_delete_token),
)
2023-06-06 08:19:54 +00:00
.route(
"/user/delete_account",
web::post().to(user_controller::delete_account),
)
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
}