Working actix_files and vite configuration for serving static build

This commit is contained in:
Imbus 2023-10-17 03:04:42 +02:00
parent 118ee088b4
commit 89c949ac50
5 changed files with 76 additions and 11 deletions

View file

@ -4,6 +4,9 @@ import { qrcode } from 'vite-plugin-qrcode'
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
build: {
outDir: '../server/public'
},
plugins: [react(), qrcode()], plugins: [react(), qrcode()],
server: { server: {
port: 3000, port: 3000,

1
server/.gitignore vendored
View file

@ -1 +1,2 @@
/target /target
/public

55
server/Cargo.lock generated
View file

@ -19,6 +19,29 @@ dependencies = [
"tracing", "tracing",
] ]
[[package]]
name = "actix-files"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d832782fac6ca7369a70c9ee9a20554623c5e51c76e190ad151780ebea1cf689"
dependencies = [
"actix-http",
"actix-service",
"actix-utils",
"actix-web",
"askama_escape",
"bitflags 1.3.2",
"bytes",
"derive_more",
"futures-core",
"http-range",
"log",
"mime",
"mime_guess",
"percent-encoding",
"pin-project-lite",
]
[[package]] [[package]]
name = "actix-http" name = "actix-http"
version = "3.4.0" version = "3.4.0"
@ -314,6 +337,12 @@ dependencies = [
"zeroize", "zeroize",
] ]
[[package]]
name = "askama_escape"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341"
[[package]] [[package]]
name = "atoi" name = "atoi"
version = "2.0.0" version = "2.0.0"
@ -1016,6 +1045,12 @@ dependencies = [
"itoa", "itoa",
] ]
[[package]]
name = "http-range"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573"
[[package]] [[package]]
name = "httparse" name = "httparse"
version = "1.8.0" version = "1.8.0"
@ -1262,6 +1297,16 @@ version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]]
name = "mime_guess"
version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef"
dependencies = [
"mime",
"unicase",
]
[[package]] [[package]]
name = "minimal-lexical" name = "minimal-lexical"
version = "0.2.1" version = "0.2.1"
@ -1732,6 +1777,7 @@ dependencies = [
name = "server" name = "server"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"actix-files",
"actix-web", "actix-web",
"argon2", "argon2",
"chrono", "chrono",
@ -2281,6 +2327,15 @@ version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "unicase"
version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89"
dependencies = [
"version_check",
]
[[package]] [[package]]
name = "unicode-bidi" name = "unicode-bidi"
version = "0.3.13" version = "0.3.13"

View file

@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
actix-files = "0.6.2"
actix-web = "4.4.0" actix-web = "4.4.0"
argon2 = { version = "0.5.2", features = ["zeroize"] } argon2 = { version = "0.5.2", features = ["zeroize"] }
chrono = { version = "0.4.31", features = ["serde"] } chrono = { version = "0.4.31", features = ["serde"] }

View file

@ -1,4 +1,5 @@
// #![allow(dead_code, unused_imports)] use actix_files::Files;
use actix_web::middleware;
use actix_web::web::Data; use actix_web::web::Data;
use actix_web::{web::scope, App, HttpServer}; use actix_web::{web::scope, App, HttpServer};
use log::info; use log::info;
@ -19,16 +20,20 @@ async fn main() -> std::io::Result<()> {
info!("Spinning up server on http://localhost:8080"); info!("Spinning up server on http://localhost:8080");
HttpServer::new(move || { HttpServer::new(move || {
App::new().service( App::new()
scope("api") .wrap(middleware::Compress::default())
.service(get_posts) .wrap(middleware::Logger::default())
.service(new_post) .service(
.service(routes::vote) scope("/api")
.service(test) .service(get_posts)
.service(login) .service(new_post)
.service(register) .service(routes::vote)
.app_data(Data::new(data.clone())), .service(test)
) .service(login)
.service(register)
.app_data(Data::new(data.clone())),
)
.service(Files::new("/", "./public").index_file("index.html"))
}) })
.bind("localhost:8080")? .bind("localhost:8080")?
.run() .run()