Remove more files supporting the old web front-end
This commit is contained in:
parent
9f0b044ba0
commit
9f83417b58
92 changed files with 17 additions and 1935 deletions
|
@ -1,10 +1,8 @@
|
|||
mod api;
|
||||
mod assets;
|
||||
mod auth;
|
||||
mod db;
|
||||
mod env;
|
||||
mod errors;
|
||||
mod expiring;
|
||||
mod github;
|
||||
mod rpc;
|
||||
|
||||
|
@ -12,36 +10,21 @@ use ::rpc::Peer;
|
|||
use async_std::net::TcpListener;
|
||||
use async_trait::async_trait;
|
||||
use db::{Db, PostgresDb};
|
||||
use handlebars::Handlebars;
|
||||
use parking_lot::RwLock;
|
||||
use rust_embed::RustEmbed;
|
||||
use serde::Deserialize;
|
||||
use std::sync::Arc;
|
||||
use surf::http::cookies::SameSite;
|
||||
use tide::sessions::SessionMiddleware;
|
||||
use tide_compress::CompressMiddleware;
|
||||
|
||||
type Request = tide::Request<Arc<AppState>>;
|
||||
|
||||
#[derive(RustEmbed)]
|
||||
#[folder = "templates"]
|
||||
struct Templates;
|
||||
|
||||
#[derive(Default, Deserialize)]
|
||||
pub struct Config {
|
||||
pub http_port: u16,
|
||||
pub database_url: String,
|
||||
pub session_secret: String,
|
||||
pub github_app_id: usize,
|
||||
pub github_client_id: String,
|
||||
pub github_client_secret: String,
|
||||
pub github_private_key: String,
|
||||
pub api_token: String,
|
||||
}
|
||||
|
||||
pub struct AppState {
|
||||
db: Arc<dyn Db>,
|
||||
handlebars: RwLock<Handlebars<'static>>,
|
||||
config: Config,
|
||||
}
|
||||
|
||||
|
@ -51,27 +34,10 @@ impl AppState {
|
|||
|
||||
let this = Self {
|
||||
db: Arc::new(db),
|
||||
handlebars: Default::default(),
|
||||
config,
|
||||
};
|
||||
this.register_partials();
|
||||
Ok(Arc::new(this))
|
||||
}
|
||||
|
||||
fn register_partials(&self) {
|
||||
for path in Templates::iter() {
|
||||
if let Some(partial_name) = path
|
||||
.strip_prefix("partials/")
|
||||
.and_then(|path| path.strip_suffix(".hbs"))
|
||||
{
|
||||
let partial = Templates::get(path.as_ref()).unwrap();
|
||||
self.handlebars
|
||||
.write()
|
||||
.register_partial(partial_name, std::str::from_utf8(&partial.data).unwrap())
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
@ -120,26 +86,12 @@ pub async fn run_server(
|
|||
) -> tide::Result<()> {
|
||||
let mut web = tide::with_state(state.clone());
|
||||
web.with(CompressMiddleware::new());
|
||||
web.with(
|
||||
SessionMiddleware::new(
|
||||
db::SessionStore::new_with_table_name(&state.config.database_url, "sessions")
|
||||
.await
|
||||
.unwrap(),
|
||||
state.config.session_secret.as_bytes(),
|
||||
)
|
||||
.with_same_site_policy(SameSite::Lax), // Required obtain our session in /auth_callback
|
||||
);
|
||||
api::add_routes(&mut web);
|
||||
|
||||
let mut assets = tide::new();
|
||||
assets.with(CompressMiddleware::new());
|
||||
assets::add_routes(&mut assets);
|
||||
|
||||
let mut app = tide::with_state(state.clone());
|
||||
rpc::add_routes(&mut app, &rpc);
|
||||
|
||||
app.at("/").nest(web);
|
||||
app.at("/static").nest(assets);
|
||||
|
||||
app.listen(listener).await?;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue