Compare commits

..

No commits in common. "cfaf7ecc1fe0e55e8ed193cbb54cf6a5f1027897" and "e0e8700baafdbe9f991f2b0ece65e5837b41d126" have entirely different histories.

10 changed files with 59 additions and 1620 deletions

3
.devfiles/init-bun.ts Normal file
View file

@ -0,0 +1,3 @@
import sassPlugin from "@alecodes/bun-plugin-sass";
Bun.plugin(sassPlugin);

View file

@ -3,6 +3,10 @@ mod repo ".devfiles/justfile"
set dotenv-load := true set dotenv-load := true
set shell := ["zsh", "-uc"]
build_mode := env("BUILD_MODE", "DEVELOPMENT")
[private] [private]
docker-compose +ARGS: docker-compose +ARGS:
docker compose --file .devfiles/docker/docker-compose.dev.yaml --env-file .env --project-name compendium {{ARGS}} docker compose --file .devfiles/docker/docker-compose.dev.yaml --env-file .env --project-name compendium {{ARGS}}
@ -10,31 +14,20 @@ docker-compose +ARGS:
start-dev-services: (docker-compose "up --remove-orphans") start-dev-services: (docker-compose "up --remove-orphans")
dev: dev:
watchexec --restart --clear --watch src --watch dist cargo run watchexec --restart --clear --watch src --watch templates cargo run
migrate: (docker-compose "run dbmate migrate") migrate: (docker-compose "run dbmate migrate")
rollback: (docker-compose "run dbmate rollback") rollback: (docker-compose "run dbmate rollback")
build-frontend: build-frontend:
#!/usr/bin/env bun bun build \
import sassPlugin from "@alecodes/bun-plugin-sass"; {{ if uppercase(build_mode) == "DEVELOPMENT" { "--watch" } else { "" } }} \
--outdir 'dist' \
const entrypoints = Array.from( --public-path '/' \
new Bun.Glob("frontend/**/*.html").scanSync(".") --entry-naming '[dir]/[name].[ext]' \
); --chunk-naming 'assets/[name]-[hash].[ext]' \
--asset-naming 'assets/[name]-[hash].[ext]' \
const result = await Bun.build({ --splitting \
entrypoints, --css-chunking \
outdir: "dist", {{ './frontend/**/*.html' }}
publicPath: "/",
splitting: true,
plugins: [sassPlugin],
naming: {
entry: "[dir]/[name].[ext]",
chunk: "assets/[name]-[hash].[ext]",
asset: "assets/[name]-[hash].[ext]",
},
});
console.log("Assets compiled!");

1566
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -5,18 +5,10 @@ edition = "2021"
[dependencies] [dependencies]
axum = "0.8.1" axum = "0.8.1"
axum-sqlx-tx = "0.10.0"
minijinja = { version = "2.7.0", features = ["loader"] } minijinja = { version = "2.7.0", features = ["loader"] }
minijinja-embed = "2.7.0" minijinja-embed = "2.7.0"
notify = "8.0.0" notify = "8.0.0"
serde = { version = "1.0.217", features = ["derive"] } serde = { version = "1.0.217", features = ["derive"] }
sqlx = { version = "0.8.3", features = [
"chrono",
"derive",
"json",
"postgres",
"runtime-tokio",
] }
thiserror = "2.0.11" thiserror = "2.0.11"
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] } tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
tower-http = { version = "0.6.2", features = ["fs", "trace"] } tower-http = { version = "0.6.2", features = ["fs", "trace"] }

View file

@ -1,3 +1,5 @@
preload = ["./.devfiles/init-bun.ts"]
[serve.static] [serve.static]
plugins = ["bun-plugin-sass"] plugins = ["bun-plugin-sass"]

View file

@ -1,3 +1,3 @@
h1 { h1 {
color: red; color: blue;
} }

View file

@ -0,0 +1,21 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../css/style.css" />
<title>
{% block title %}Axum web service!{% endblock %}
</title>
</head>
<body>
{% include "partials/header.html" %}
<main>
<nav class="msp-d-sm-none msp-d-flex msp-justify-content-end">
<button class="msp-offcanvas-toggle" data-msp-target="#main-offcanvas">Toggle</button>
</nav>
{% block content %}{% endblock %}
</main>
</body>
</html>

View file

@ -19,17 +19,13 @@ pub enum Error {
#[error(transparent)] #[error(transparent)]
IO(#[from] std::io::Error), IO(#[from] std::io::Error),
#[error(transparent)]
Env(#[from] std::env::VarError),
#[error(transparent)] #[error(transparent)]
Template(#[from] minijinja::Error), Template(#[from] minijinja::Error),
#[error("Error in runtime execution: {0}")] #[error("Error in runtime execution: {0}")]
Runtime(&'static str), Runtime(&'static str),
// #[error(transparent)]
#[error(transparent)] // DatabaseOperation(#[from] sqlx::Error),
DatabaseOperation(#[from] sqlx::Error),
} }
impl IntoResponse for Error { impl IntoResponse for Error {

View file

@ -6,8 +6,6 @@ use minijinja::{Environment, Template};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::sync::Arc; use std::sync::Arc;
pub type Tx = axum_sqlx_tx::Tx<sqlx::Postgres>;
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct Link { pub struct Link {
pub path: String, pub path: String,

View file

@ -1,11 +1,8 @@
#![allow(unused)] #![allow(unused)]
#![allow(dead_code)] #![allow(dead_code)]
use compendium::{router, AppState, Error, Link, Result, Tx}; use compendium::{router, AppState, Error, Link, Result};
use minijinja::{Environment, Value}; use minijinja::{Environment, Value};
use sqlx::postgres::PgPoolOptions;
use sqlx::PgPool;
use std::env;
use std::sync::Arc; use std::sync::Arc;
use tower_http::trace::TraceLayer; use tower_http::trace::TraceLayer;
use tracing::info; use tracing::info;
@ -40,23 +37,6 @@ fn load_templates() -> Result<Environment<'static>> {
Ok(tmpl_env) Ok(tmpl_env)
} }
async fn init_db() -> Result<PgPool> {
let db_string = format!(
"postgres://{}:{}@{}/{}",
env::var("CPD_DB_USER")?,
env::var("CPD_DB_PASSWORD")?,
env::var("CPD_DB_HOST")?,
env::var("CPD_DB_NAME")?
);
info!("Connecting to database {}", db_string);
Ok(PgPoolOptions::new()
.max_connections(5)
.connect(&db_string)
.await?)
}
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
// Logs // Logs
@ -71,15 +51,9 @@ async fn main() -> Result<()> {
let mut tmpl_env = load_templates()?; let mut tmpl_env = load_templates()?;
let pool = init_db().await?;
let (tx_state, tx_layer) = Tx::setup(pool);
let app = router::new() let app = router::new()
.layer(TraceLayer::new_for_http().on_request(())) .layer(TraceLayer::new_for_http().on_request(()))
.with_state(AppState::new(tmpl_env)) .with_state(AppState::new(tmpl_env));
.layer(tx_layer)
.with_state(tx_state);
// Add hot reload only on dev mode // Add hot reload only on dev mode
#[cfg(debug_assertions)] #[cfg(debug_assertions)]