Add Backend

This commit is contained in:
BloxerHD 2026-06-23 17:17:57 +01:00
commit 05beab587b
Signed by: bloxerhd018
SSH key fingerprint: SHA256:ItSfcfhpXlfkMK3uQSDYW5X3XKm0hbHWQqWcCK57px8
31 changed files with 59 additions and 6 deletions

3
.gitignore vendored
View file

@ -1 +1,4 @@
.vscode
target
.env
Cargo.lock

10
Cargo.toml Normal file
View file

@ -0,0 +1,10 @@
[package]
name = "spfn-website"
version = "0.1.0"
edition = "2024"
[dependencies]
axum = "0.8.9"
dotenvy = "0.15.7"
tokio = { version = "1.52.3", features = ["full"] }
tower-http = { version = "0.7.0", features = ["fs"] }

View file

@ -1,13 +1,28 @@
# syntax=docker/dockerfile:1
FROM nginx:alpine
FROM rust:alpine AS builder
WORKDIR /usr/share/nginx/html
RUN apk add --no-cache musl-dev openssl-dev openssl-libs-static protobuf-dev lld
WORKDIR /app
COPY Cargo.toml ./
RUN mkdir src && echo "fn main() {}" > src/main.rs && cargo fetch
COPY . .
RUN rm -rf .git
ENV SQLX_OFFLINE=true
EXPOSE 80
RUN OPENSSL_LIB_DIR=/usr/lib OPENSSL_INCLUDE_DIR=/usr/include/openssl OPENSSL_STATIC=1 RUSTFLAGS="-C target-feature=+aes,+sse -C relocation-model=static -C linker=ld.lld" cargo build --release --target x86_64-unknown-linux-musl
CMD ["nginx", "-g", "daemon off;"]
FROM alpine:latest AS final
RUN apk add --no-cache ca-certificates
RUN update-ca-certificates
WORKDIR /
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/spfn-website /spfn-website
COPY --from=builder /app/static /static
ENTRYPOINT ["/spfn-website"]

25
src/main.rs Normal file
View file

@ -0,0 +1,25 @@
use std::env;
use axum::Router;
use tower_http::services::ServeDir;
use dotenvy::dotenv;
#[tokio::main]
async fn main() {
dotenv().ok();
let host = env::var("APP_HOST").unwrap_or("0.0.0.0".into());
let port = env::var("APP_PORT").unwrap_or("80".into());
let app = Router::new()
.fallback_service(ServeDir::new("static"));
let listener = tokio::net::TcpListener::bind(format!("{}:{}", host, port))
.await
.unwrap();
println!("Website Hosting with Host {} and Port {}", host, port);
axum::serve(listener, app)
.await
.unwrap();
}

View file

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 99 KiB

After

Width:  |  Height:  |  Size: 99 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 272 KiB

After

Width:  |  Height:  |  Size: 272 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 85 KiB

After

Width:  |  Height:  |  Size: 85 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 761 KiB

After

Width:  |  Height:  |  Size: 761 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 107 KiB

After

Width:  |  Height:  |  Size: 107 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Before After
Before After