2023-10-10 00:03:04 +02:00
|
|
|
#![allow(dead_code, unused_imports)]
|
|
|
|
use actix_web::web::{Data, Query};
|
2023-10-09 19:21:55 +02:00
|
|
|
use actix_web::{web::scope, App, HttpServer};
|
2023-10-10 00:03:04 +02:00
|
|
|
use log::info;
|
2023-10-09 19:21:55 +02:00
|
|
|
// use uuid::Uuid;
|
|
|
|
|
|
|
|
mod routes;
|
2023-10-10 00:03:04 +02:00
|
|
|
mod state;
|
2023-10-09 19:21:55 +02:00
|
|
|
mod types;
|
|
|
|
|
2023-10-10 00:03:04 +02:00
|
|
|
use routes::{get_posts, new_post, register, test};
|
|
|
|
use sqlx::ConnectOptions;
|
|
|
|
use state::AppState;
|
|
|
|
|
|
|
|
use sqlx::{migrate::MigrateDatabase, query, sqlite};
|
|
|
|
|
|
|
|
struct User {
|
|
|
|
name: String,
|
|
|
|
pass: String,
|
|
|
|
}
|
2023-10-09 19:21:55 +02:00
|
|
|
|
|
|
|
#[actix_web::main]
|
|
|
|
async fn main() -> std::io::Result<()> {
|
|
|
|
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("debug")).init();
|
|
|
|
|
2023-10-10 00:03:04 +02:00
|
|
|
let data = AppState::new().await;
|
2023-10-09 19:21:55 +02:00
|
|
|
|
2023-10-10 00:03:04 +02:00
|
|
|
info!("Spinning up server on http://localhost:8080");
|
2023-10-09 19:21:55 +02:00
|
|
|
HttpServer::new(move || {
|
|
|
|
App::new().service(
|
|
|
|
scope("api")
|
|
|
|
.service(get_posts)
|
|
|
|
.service(new_post)
|
|
|
|
.service(routes::vote)
|
|
|
|
.service(test)
|
2023-10-10 00:03:04 +02:00
|
|
|
.service(register)
|
2023-10-09 19:21:55 +02:00
|
|
|
.app_data(Data::new(data.clone())),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.bind("localhost:8080")?
|
|
|
|
.run()
|
|
|
|
.await
|
|
|
|
}
|