feat: initialize thoughts-frontend with Next.js, TypeScript, and ESLint
- Add ESLint configuration for Next.js and TypeScript support. - Create Next.js configuration file with standalone output option. - Initialize package.json with scripts for development, build, and linting. - Set up PostCSS configuration for Tailwind CSS. - Add SVG assets for UI components. - Create TypeScript configuration for strict type checking and module resolution.
This commit is contained in:
27
thoughts-backend/src/main.rs
Normal file
27
thoughts-backend/src/main.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
#[cfg(not(feature = "shuttle"))]
|
||||
mod tokio;
|
||||
|
||||
#[cfg(not(feature = "shuttle"))]
|
||||
fn main() {
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
|
||||
tracing_subscriber::registry()
|
||||
.with(
|
||||
tracing_subscriber::EnvFilter::try_from_default_env()
|
||||
.unwrap_or_else(|_| "api=debug,clean_axum=debug,tower_http=debug".into()),
|
||||
)
|
||||
.with(tracing_subscriber::fmt::layer())
|
||||
.init();
|
||||
|
||||
tracing::info!("Starting with tokio");
|
||||
tokio::run();
|
||||
}
|
||||
|
||||
#[cfg(feature = "shuttle")]
|
||||
mod shuttle;
|
||||
|
||||
#[cfg(feature = "shuttle")]
|
||||
#[shuttle_runtime::main]
|
||||
async fn main(#[shuttle_shared_db::Postgres] db_url: String) -> shuttle_axum::ShuttleAxum {
|
||||
shuttle::run(&db_url).await
|
||||
}
|
13
thoughts-backend/src/shuttle.rs
Normal file
13
thoughts-backend/src/shuttle.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
use api::{setup_db, setup_router};
|
||||
use doc::ApiDoc;
|
||||
use utils::migrate;
|
||||
|
||||
pub async fn run(db_url: &str) -> shuttle_axum::ShuttleAxum {
|
||||
tracing::info!("Starting with shuttle");
|
||||
|
||||
let conn = setup_db(&db_url, false).await;
|
||||
migrate(&conn).await.expect("Migration failed!");
|
||||
|
||||
let router = setup_router(conn).attach_doc();
|
||||
Ok(router.into())
|
||||
}
|
58
thoughts-backend/src/tokio.rs
Normal file
58
thoughts-backend/src/tokio.rs
Normal file
@@ -0,0 +1,58 @@
|
||||
use api::{setup_config, setup_db, setup_router};
|
||||
use doc::ApiDoc;
|
||||
use utils::{create_dev_db, migrate};
|
||||
|
||||
async fn worker(child_num: u32, db_url: &str, prefork: bool, listener: std::net::TcpListener) {
|
||||
tracing::info!("Worker {} started", child_num);
|
||||
|
||||
let conn = setup_db(db_url, prefork).await;
|
||||
|
||||
if child_num == 0 {
|
||||
migrate(&conn).await.expect("Migration failed!");
|
||||
}
|
||||
|
||||
let router = setup_router(conn).attach_doc();
|
||||
|
||||
let listener = tokio::net::TcpListener::from_std(listener).expect("bind to port");
|
||||
axum::serve(listener, router).await.expect("start server");
|
||||
}
|
||||
|
||||
#[cfg(feature = "prefork")]
|
||||
fn run_prefork(db_url: &str, listener: std::net::TcpListener) {
|
||||
let db_url: &'static str = Box::leak(db_url.to_owned().into_boxed_str());
|
||||
create_dev_db(db_url);
|
||||
|
||||
let num_of_cores = std::thread::available_parallelism().unwrap().get() as u32;
|
||||
let is_parent = prefork::Prefork::from_resource(listener)
|
||||
.with_num_processes(num_of_cores)
|
||||
.with_tokio(move |child_num, listener| worker(child_num, db_url, true, listener))
|
||||
.fork()
|
||||
.expect("prefork failed");
|
||||
|
||||
if is_parent {
|
||||
tracing::info!("All workers stopped");
|
||||
}
|
||||
}
|
||||
|
||||
fn run_non_prefork(db_url: &str, listener: std::net::TcpListener) {
|
||||
create_dev_db(db_url);
|
||||
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(worker(0, db_url, false, listener));
|
||||
}
|
||||
|
||||
pub fn run() {
|
||||
let config = setup_config();
|
||||
|
||||
let listener = std::net::TcpListener::bind(config.get_server_url()).expect("bind to port");
|
||||
listener.set_nonblocking(true).expect("non blocking failed");
|
||||
tracing::debug!("listening on http://{}", listener.local_addr().unwrap());
|
||||
|
||||
#[cfg(feature = "prefork")]
|
||||
if config.prefork {
|
||||
run_prefork(&config.db_url, listener);
|
||||
return;
|
||||
}
|
||||
|
||||
run_non_prefork(&config.db_url, listener);
|
||||
}
|
Reference in New Issue
Block a user