Revert "almost production ready"

This reverts commit 937b3fc811.
This commit is contained in:
WaveringAna 2025-01-26 01:45:50 -05:00
parent 937b3fc811
commit f3a61bfa99
21 changed files with 55 additions and 1071 deletions

View file

@ -1,15 +1,10 @@
use actix_cors::Cors;
use actix_files::Files;
use actix_web::{middleware::DefaultHeaders, web, App, HttpServer};
use actix_web::{web, App, HttpServer};
use anyhow::Result;
use simplelink::{handlers, AppState};
use simple_link::{handlers, AppState};
use sqlx::postgres::PgPoolOptions;
use tracing::info;
async fn index() -> Result<actix_files::NamedFile, actix_web::Error> {
Ok(actix_files::NamedFile::open("./static/index.html")?)
}
#[actix_web::main]
async fn main() -> Result<()> {
// Load environment variables from .env file
@ -31,10 +26,10 @@ async fn main() -> Result<()> {
// Run database migrations
sqlx::migrate!("./migrations").run(&pool).await?;
let _state = AppState { db: pool };
let state = AppState { db: pool };
let host = std::env::var("SERVER_HOST").unwrap_or_else(|_| "127.0.0.1".to_string());
let port = std::env::var("SERVER_PORT").unwrap_or_else(|_| "3000".to_string());
let port = std::env::var("SERVER_PORT").unwrap_or_else(|_| "8080".to_string());
info!("Starting server at http://{}:{}", host, port);
// Start HTTP server
@ -47,31 +42,20 @@ async fn main() -> Result<()> {
App::new()
.wrap(cors)
// Add headers to help with caching static assets
.wrap(DefaultHeaders::new().add(("Cache-Control", "max-age=31536000")))
// API routes
.app_data(web::Data::new(state.clone()))
.service(
web::scope("/api")
.route("/shorten", web::post().to(handlers::create_short_url))
.route("/links", web::get().to(handlers::get_all_links))
.route("/links/{id}", web::delete().to(handlers::delete_link))
.route(
"/links/{id}/clicks",
web::get().to(handlers::get_link_clicks),
)
.route(
"/links/{id}/sources",
web::get().to(handlers::get_link_sources),
)
.route("/auth/register", web::post().to(handlers::register))
.route("/auth/login", web::post().to(handlers::login))
.route("/health", web::get().to(handlers::health_check)),
)
// Serve static files
.service(Files::new("/assets", "./static/assets"))
// Handle SPA routes - must be last
.default_service(web::get().to(index))
.service(web::resource("/{short_code}").route(web::get().to(handlers::redirect_to_url)))
})
.workers(2)
.backlog(10_000)
.bind(format!("{}:{}", host, port))?
.run()
.await?;