-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.rs
33 lines (27 loc) · 862 Bytes
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#[macro_use]
extern crate diesel;
mod models;
mod routes;
mod schema;
use actix_web::{web, App, HttpServer};
use diesel::r2d2::{self, ConnectionManager};
use diesel::SqliteConnection;
pub type Pool = r2d2::Pool<ConnectionManager<SqliteConnection>>;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
dotenv::dotenv().ok();
let database_url = std::env::var("DATABASE_URL").expect("NOT FOUND");
let database_pool = Pool::builder()
.build(ConnectionManager::new(database_url))
.unwrap();
HttpServer::new(move || {
App::new()
.data(database_pool.clone())
.route("/", web::get().to(routes::root))
.route("/users", web::post().to(routes::create_user))
.route("/getusers", web::get().to(routes::get_users))
})
.bind("localhost:8080")?
.run()
.await
}