frontend integration

This commit is contained in:
realaravinth
2021-04-09 14:21:43 +05:30
parent c4255397b1
commit 0496c0bdaf
95 changed files with 7115 additions and 197 deletions

View File

@@ -23,6 +23,7 @@ use actix_web::{
HttpServer,
};
//use awc::Client;
use cache_buster::Files as FileMap;
use lazy_static::lazy_static;
use log::info;
@@ -32,7 +33,7 @@ mod errors;
mod api;
mod docs;
mod settings;
//mod templates;
mod templates;
#[cfg(test)]
#[macro_use]
mod tests;
@@ -46,6 +47,11 @@ lazy_static! {
// pub static ref OPEN_API_DOC: String = env::var("OPEN_API_DOCS").unwrap();
pub static ref S: String = env::var("S").unwrap();
pub static ref FILES: FileMap = FileMap::load();
pub static ref JS: &'static str = FILES.get("./static/bundle/main.js").unwrap();
pub static ref CSS: &'static str = FILES.get("./static/bundle/main.css").unwrap();
}
pub static OPEN_API_DOC: &str = env!("OPEN_API_DOCS");
@@ -84,8 +90,9 @@ async fn main() -> std::io::Result<()> {
))
.configure(v1::services)
.configure(docs::services)
.configure(templates::services)
.app_data(get_json_err())
.service(Files::new("/", "./frontend/dist").index_file("index.html"))
.service(Files::new("/", "./prod"))
})
.bind(SETTINGS.server.get_ip())
.unwrap()

View File

@@ -0,0 +1,34 @@
use actix_web::{get, HttpResponse, Responder};
use sailfish::TemplateOnce;
#[derive(Clone, TemplateOnce)]
#[template(path = "auth/login/index.html")]
struct IndexPage {
name: String,
title: String,
}
impl Default for IndexPage {
fn default() -> Self {
IndexPage {
name: "mCaptcha".into(),
title: "Login".into(),
}
}
}
impl IndexPage {
pub fn run(&self) -> Result<String, &'static str> {
let index = self.clone().render_once().unwrap();
Ok(index)
}
}
#[get("/")]
pub async fn login() -> impl Responder {
let body = IndexPage::default().run().unwrap();
HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(body)
}

View File

@@ -0,0 +1,2 @@
pub mod login;
pub mod register;

View File

@@ -0,0 +1,34 @@
use actix_web::{get, HttpResponse, Responder};
use sailfish::TemplateOnce;
#[derive(TemplateOnce, Clone)]
#[template(path = "auth/register/index.html")]
pub struct IndexPage {
pub name: String,
pub title: String,
}
impl Default for IndexPage {
fn default() -> Self {
IndexPage {
name: "mCaptcha".into(),
title: "Join".into(),
}
}
}
impl IndexPage {
pub fn run(&self) -> Result<String, &'static str> {
let index = self.clone().render_once().unwrap();
Ok(index)
}
}
#[get("/join")]
pub async fn join() -> impl Responder {
let body = IndexPage::default().run().unwrap();
HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(body)
}

View File

@@ -17,8 +17,11 @@
use actix_web::web::ServiceConfig;
mod routes;
mod auth;
mod panel;
pub fn services(cfg: &mut ServiceConfig) {
cfg.service(routes::login);
cfg.service(auth::login::login);
cfg.service(auth::register::join);
cfg.service(panel::panel);
}

View File

@@ -0,0 +1,35 @@
use actix_web::{get, HttpResponse, Responder};
use sailfish::TemplateOnce;
#[derive(TemplateOnce, Clone)]
#[template(path = "panel/index.html")]
pub struct IndexPage {
pub name: String,
pub title: String,
}
const TITLE: &str = "Dashboard";
impl Default for IndexPage {
fn default() -> Self {
IndexPage {
name: "mCaptcha".into(),
title: "Home".into(),
}
}
}
impl IndexPage {
pub fn run(&self) -> Result<String, &'static str> {
let index = self.clone().render_once().unwrap();
Ok(index)
}
}
#[get("/panel")]
pub async fn panel() -> impl Responder {
let body = IndexPage::default().run().unwrap();
HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(body)
}

View File

@@ -16,19 +16,13 @@
*/
use sailfish::TemplateOnce;
//use au
#[derive(TemplateOnce, Default)]
#[template(path = "signin.stpl")]
struct SignIn;
use actix_web::{get, post, web, HttpResponse, Responder};
//use awc::Client;
#[get("/login/")]
pub async fn login() -> impl Responder {
let body = SignIn::default().render_once().unwrap();
// .map_err(|_| ServiceError::InternalError)?;
HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(body)
}
//#[get("/")]
//pub async fn login() -> impl Responder {
// let body = SignIn::default().render_once().unwrap();
// // .map_err(|_| ServiceError::InternalError)?;
// HttpResponse::Ok()
// .content_type("text/html; charset=utf-8")
// .body(body)
//}