feat: save sites and report db health
This commit is contained in:
parent
5bf8ed61db
commit
22e7bc29fa
5 changed files with 44 additions and 6 deletions
4
migrations/20220909090742_forms_websites.sql
Normal file
4
migrations/20220909090742_forms_websites.sql
Normal file
|
@ -0,0 +1,4 @@
|
|||
CREATE TABLE IF NOT EXISTS forms_websites (
|
||||
hostname VARCHAR(2500) NOT NULL UNIQUE,
|
||||
ID SERIAL PRIMARY KEY NOT NULL
|
||||
)
|
27
sqlx-data.json
Normal file
27
sqlx-data.json
Normal file
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"db": "PostgreSQL",
|
||||
"d184df863185d97345d5de3b80823312053a7a38316fd8b3c8fdd32d9a29644a": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"nullable": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Varchar"
|
||||
]
|
||||
}
|
||||
},
|
||||
"query": "INSERT INTO forms_websites (hostname) VALUES ($1) ON CONFLICT DO NOTHING;"
|
||||
},
|
||||
"d548953611b4fccb07ef22cb185deac69e4feb79864fcc98f2dc868298587315": {
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"nullable": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
}
|
||||
},
|
||||
"query": "DELETE FROM forms_websites WHERE hostname = ($1)"
|
||||
}
|
||||
}
|
|
@ -16,11 +16,12 @@
|
|||
*/
|
||||
use std::collections::HashMap;
|
||||
|
||||
use actix_web::{web, Error, HttpRequest, HttpResponse, Responder};
|
||||
use actix_web::{web, HttpRequest, HttpResponse, Responder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::API_V1_ROUTES;
|
||||
use crate::errors::*;
|
||||
use crate::AppCtx;
|
||||
use crate::*;
|
||||
|
||||
pub mod routes {
|
||||
use super::*;
|
||||
|
@ -65,11 +66,12 @@ async fn upload(
|
|||
req: HttpRequest,
|
||||
ctx: AppCtx,
|
||||
payload: web::Either<web::Json<serde_json::Value>, web::Form<FormValue>>,
|
||||
) -> Result<impl Responder, Error> {
|
||||
) -> ServiceResult<impl Responder> {
|
||||
let c = req.connection_info();
|
||||
let host = c.host();
|
||||
let path = req.uri();
|
||||
|
||||
ctx.db.add_site(host).await.unwrap();
|
||||
let data = match payload {
|
||||
web::Either::Left(json) => json.into_inner(),
|
||||
web::Either::Right(form) => {
|
||||
|
|
|
@ -64,10 +64,10 @@ pub struct Health {
|
|||
|
||||
/// checks all components of the system
|
||||
#[actix_web_codegen_const_routes::get(path = "crate::API_V1_ROUTES.meta.health")]
|
||||
async fn health() -> impl Responder {
|
||||
// let mut resp_builder = HealthBuilder::default();
|
||||
async fn health(ctx: crate::AppCtx) -> impl Responder {
|
||||
let mut resp_builder = HealthBuilder::default();
|
||||
|
||||
// resp_builder.db(data.db.ping().await);
|
||||
resp_builder.db(ctx.db.ping().await);
|
||||
|
||||
HttpResponse::Ok() //.json(resp_builder.build().unwrap())
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ use std::thread;
|
|||
use argon2_creds::{Config, ConfigBuilder, PasswordPolicy};
|
||||
|
||||
//use crate::errors::ServiceResult;
|
||||
use crate::db::*;
|
||||
use crate::settings::Settings;
|
||||
|
||||
/// App data
|
||||
|
@ -31,6 +32,7 @@ pub struct Ctx {
|
|||
/// app settings
|
||||
pub settings: Settings,
|
||||
pub source_code: String,
|
||||
pub db: Database,
|
||||
}
|
||||
|
||||
impl Ctx {
|
||||
|
@ -76,11 +78,14 @@ impl Ctx {
|
|||
base.into()
|
||||
};
|
||||
|
||||
let db = get_db(s).await;
|
||||
|
||||
let data = Ctx {
|
||||
creds,
|
||||
// db,
|
||||
settings: s.clone(),
|
||||
source_code,
|
||||
db,
|
||||
};
|
||||
|
||||
Arc::new(data)
|
||||
|
|
Loading…
Reference in a new issue