forked from Roflin/gamenight
Re-added auto migrations
This commit is contained in:
@@ -6,15 +6,22 @@ use actix_web::HttpServer;
|
||||
use actix_web::App;
|
||||
use actix_web::web;
|
||||
use diesel::PgConnection;
|
||||
use diesel::r2d2::{ConnectionManager, Pool};
|
||||
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
|
||||
use request::{login, register, gamenights, gamenight_post, gamenight_get};
|
||||
use diesel::r2d2::ConnectionManager;
|
||||
use diesel::r2d2::Pool;
|
||||
use util::GetConnection;
|
||||
|
||||
pub(crate) type DbPool = Pool<ConnectionManager<PgConnection>>;
|
||||
|
||||
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!();
|
||||
|
||||
fn run_migration(conn: &mut PgConnection) {
|
||||
conn.run_pending_migrations(MIGRATIONS).unwrap();
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
let url = "postgres://root:root@localhost/gamenight";
|
||||
let url = "postgres://root:root@127.0.0.1/gamenight";
|
||||
let manager = ConnectionManager::<PgConnection>::new(url);
|
||||
// Refer to the `r2d2` documentation for more methods to use
|
||||
// when building a connection pool
|
||||
@@ -23,6 +30,9 @@ async fn main() -> std::io::Result<()> {
|
||||
.build(manager)
|
||||
.expect("Could not build connection pool");
|
||||
|
||||
let mut conn = pool.get_conn();
|
||||
run_migration(&mut conn);
|
||||
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
.app_data(web::Data::new(pool.clone()))
|
||||
|
||||
@@ -26,8 +26,6 @@ fn get_claims(req: &HttpRequest) -> Result<Claims, ApiError> {
|
||||
message: "JWT-token was not specified in the Authorization header as Bearer: token".to_string()
|
||||
})?;
|
||||
|
||||
println!("{:?}", token);
|
||||
|
||||
let secret = "secret";
|
||||
Ok(decode::<Claims>(token.as_str(), &DecodingKey::from_secret(secret.as_bytes()), &Validation::default())?.claims)
|
||||
}
|
||||
@@ -38,8 +36,6 @@ pub fn get_token(user: &User) -> Result<String, ApiError> {
|
||||
uid: user.id,
|
||||
};
|
||||
|
||||
println!("{:?}", claims);
|
||||
|
||||
let secret = "secret";
|
||||
Ok(encode(
|
||||
&Header::default(),
|
||||
|
||||
Reference in New Issue
Block a user