Up until the database, need to get docker and CI/CD on server first
This commit is contained in:
28
src/lib.rs
Normal file
28
src/lib.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use actix_web::{dev::Server, web, App, HttpResponse, HttpServer};
|
||||
use std::net::TcpListener;
|
||||
|
||||
async fn health_check() -> HttpResponse {
|
||||
HttpResponse::Ok().finish()
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
struct FormData {
|
||||
email: String,
|
||||
name: String,
|
||||
}
|
||||
|
||||
async fn subscribe(_form: web::Form<FormData>) -> HttpResponse {
|
||||
HttpResponse::Ok().finish()
|
||||
}
|
||||
|
||||
pub fn run(listener: TcpListener) -> Result<Server, std::io::Error> {
|
||||
let server = HttpServer::new(|| {
|
||||
App::new()
|
||||
.route("/health_check", web::get().to(health_check))
|
||||
.route("/subscriptions", web::post().to(subscribe))
|
||||
})
|
||||
.listen(listener)?
|
||||
.run();
|
||||
|
||||
Ok(server)
|
||||
}
|
||||
10
src/main.rs
Normal file
10
src/main.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
use std::net::TcpListener;
|
||||
|
||||
use email_newsletter::run;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), std::io::Error> {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").expect("Failed to bind to address");
|
||||
|
||||
run(listener)?.await
|
||||
}
|
||||
Reference in New Issue
Block a user