Add Backend
5
.gitignore
vendored
|
|
@ -1 +1,4 @@
|
|||
.vscode
|
||||
.vscode
|
||||
target
|
||||
.env
|
||||
Cargo.lock
|
||||
|
|
|
|||
10
Cargo.toml
Normal 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"] }
|
||||
25
Dockerfile
|
|
@ -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
|
|
@ -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();
|
||||
}
|
||||
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 99 KiB After Width: | Height: | Size: 99 KiB |
|
Before Width: | Height: | Size: 272 KiB After Width: | Height: | Size: 272 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 85 KiB After Width: | Height: | Size: 85 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 761 KiB After Width: | Height: | Size: 761 KiB |
|
Before Width: | Height: | Size: 107 KiB After Width: | Height: | Size: 107 KiB |
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |