User authentication prototype
This commit is contained in:
29
src/main.rs
29
src/main.rs
@@ -1,13 +1,16 @@
|
||||
use std::error::Error;
|
||||
use std::env::var;
|
||||
use std::error::Error;
|
||||
|
||||
use axum::http::{HeaderValue, Method};
|
||||
use axum::routing::get;
|
||||
use axum::{serve, Router};
|
||||
use tokio::net::TcpListener;
|
||||
use sqlx::postgres::PgPool;
|
||||
use axum::{Router, serve};
|
||||
use dotenvy::dotenv;
|
||||
use sqlx::postgres::PgPool;
|
||||
use tokio::net::TcpListener;
|
||||
use tower_http::cors::CorsLayer;
|
||||
|
||||
mod users;
|
||||
use users::{login, me};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
@@ -15,12 +18,20 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let db_url = var("DATABASE_URL")?;
|
||||
let pool = PgPool::connect(&db_url).await?;
|
||||
let app = Router::new()
|
||||
.route("/", get(hello))
|
||||
.route("/status", get(status))
|
||||
.route("/me", get(me))
|
||||
.route("/login", get(login))
|
||||
.layer(
|
||||
CorsLayer::new()
|
||||
.allow_origin("http://localhost:5173".parse::<HeaderValue>().unwrap())
|
||||
.allow_methods([Method::GET])
|
||||
.allow_credentials(true),
|
||||
)
|
||||
.with_state(pool);
|
||||
let listener = TcpListener::bind("0.0.0.0:80").await?;
|
||||
let listener = TcpListener::bind("0.0.0.0:8080").await?;
|
||||
Ok(serve(listener, app).await?)
|
||||
}
|
||||
|
||||
async fn hello() -> &'static str {
|
||||
"Hello World"
|
||||
}
|
||||
async fn status() -> &'static str {
|
||||
"api online"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user