claude rework
This commit is contained in:
+24
-3
@@ -1,22 +1,39 @@
|
||||
extern crate diesel;
|
||||
extern crate dotenv;
|
||||
|
||||
use actix_cors::Cors;
|
||||
use actix_service::Service;
|
||||
use actix_web::{App, HttpResponse, HttpServer};
|
||||
use dotenv::dotenv;
|
||||
use futures::future::{ok, Either};
|
||||
use std::env;
|
||||
mod auth;
|
||||
mod database;
|
||||
mod json_serialization;
|
||||
mod models;
|
||||
mod reader;
|
||||
mod schema;
|
||||
#[cfg(test)]
|
||||
mod test_helpers;
|
||||
mod views;
|
||||
|
||||
#[actix_rt::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
dotenv().ok();
|
||||
env_logger::init();
|
||||
|
||||
HttpServer::new(|| {
|
||||
database::run_migrations(&mut database::establish_connection());
|
||||
|
||||
let frontend_origin =
|
||||
env::var("FRONTEND_ORIGIN").unwrap_or_else(|_| String::from("http://localhost:5173"));
|
||||
|
||||
HttpServer::new(move || {
|
||||
let cors = Cors::default()
|
||||
.allowed_origin(&frontend_origin)
|
||||
.allow_any_method()
|
||||
.allow_any_header()
|
||||
.supports_credentials();
|
||||
|
||||
let app = App::new()
|
||||
.wrap_fn(|req, srv| {
|
||||
let mut passed: bool;
|
||||
@@ -25,7 +42,10 @@ async fn main() -> std::io::Result<()> {
|
||||
log::info!("Request Url: {}", request_url);
|
||||
if req.path().contains("/article/") {
|
||||
match auth::process_token(&req) {
|
||||
Ok(_token) => passed = true,
|
||||
Ok(user_id) => {
|
||||
log::info!("Authenticated user {} for {}", user_id, request_url);
|
||||
passed = true;
|
||||
}
|
||||
Err(_message) => passed = false,
|
||||
}
|
||||
} else {
|
||||
@@ -52,10 +72,11 @@ async fn main() -> std::io::Result<()> {
|
||||
Ok(result)
|
||||
}
|
||||
})
|
||||
.wrap(cors)
|
||||
.configure(views::views_factory);
|
||||
app
|
||||
})
|
||||
.bind("127.0.0.1:8001")?
|
||||
.bind("0.0.0.0:8001")?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user