get it to run with docker

This commit is contained in:
blek 2023-09-30 19:26:47 +10:00
parent 5cdfd6135c
commit 6b99a872ec
Signed by: blek
GPG Key ID: 14546221E3595D0C
13 changed files with 102 additions and 9 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
docker-compose.yml

3
conf/caddy/Caddyfile Normal file
View File

@ -0,0 +1,3 @@
:80 {
reverse_proxy http://filed
}

21
docker-compose.dev.yml Normal file
View File

@ -0,0 +1,21 @@
version: '3.7'
services:
filed:
build:
context: filed
dockerfile: Dockerfile.dev
networks:
bfile:
volumes:
- './filed:/opt/code'
caddy:
image: caddy:alpine
volumes:
- './conf/caddy:/etc/caddy:ro'
ports:
- 80:80
networks:
bfile:
networks:
bfile:

View File

@ -1,2 +1,2 @@
APP_LOGGING=true
APP_HOST=0.0.0.0:8080
APP_HOST=0.0.0.0:80

14
filed/Cargo.lock generated
View File

@ -210,8 +210,10 @@ name = "filed"
version = "0.1.0"
dependencies = [
"askama",
"bytes",
"dotenvy",
"femme",
"futures-util",
"log",
"tokio",
"warp",
@ -248,6 +250,17 @@ version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c"
[[package]]
name = "futures-macro"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "futures-sink"
version = "0.3.28"
@ -267,6 +280,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"
dependencies = [
"futures-core",
"futures-macro",
"futures-sink",
"futures-task",
"pin-project-lite",

View File

@ -7,8 +7,10 @@ edition = "2021"
[dependencies]
askama = "0.12.0"
bytes = "1.5.0"
dotenvy = "0.15.7"
femme = "2.2.1"
futures-util = "0.3.28"
log = "0.4.20"
tokio = { version = "1.32.0", features = ["rt", "macros", "rt-multi-thread"] }
warp = "0.3.6"

View File

@ -4,11 +4,14 @@ FROM rust as builder
WORKDIR /opt/code
COPY . .
# No build or install is done during this step
# No build is done during this step
# since the directory will be mounted anyways
# to the dev's machine.
# Therefore installing & compiling in the dockerfile
# would be moronic, to say at least
CMD [ "dev-entry.sh" ]
# However, cargo watch needs to be installed
RUN cargo install cargo-watch
CMD [ "/opt/code/dev-entry.sh" ]

View File

@ -1,5 +1,7 @@
#!/bin/sh
cd /opt/code
cargo check
cargo build

30
filed/src/web/forms.rs Normal file
View File

@ -0,0 +1,30 @@
/*
forms.rs - All the forms
*/
use std::collections::HashMap;
use warp::{Filter, reply::{Html, Reply}, reject::Rejection, filters::multipart::FormData};
use futures_util::TryStreamExt;
use bytes::BufMut;
pub async fn upload(form: FormData) -> Result<Box<dyn Reply>, Rejection> {
let params: HashMap<String, String> = form.and_then(|mut field| async move {
let mut bytes: Vec<u8> = vec![];
while let Some(byte) = field.data().await {
bytes.put(byte.unwrap())
}
Ok((field.name().into(), String::from_utf8_lossy(&bytes).to_string()))
}).try_collect().await.unwrap();
Ok(Box::new(warp::reply::json(&params)))
}
pub fn get_routes() -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
warp::post().and(
warp::multipart::form().and_then(upload)
)
}

View File

@ -9,11 +9,15 @@ use warp::{Filter, reply::Reply, reject::Rejection};
use crate::env::Env;
mod pages;
mod forms;
pub fn routes() -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
let staticpath = current_dir().unwrap();
let staticpath = staticpath.to_str().unwrap().to_string() + "/static";
pages::get_routes().or(warp::fs::dir(staticpath.to_string()))
pages::get_routes()
.or(forms::get_routes())
.or(warp::fs::dir(staticpath.to_string()))
}
/*

View File

@ -7,9 +7,7 @@ use askama::Template;
#[derive(Template)]
#[template( path = "index.html" )]
struct Index {
}
struct Index {}
pub fn index() -> Html<String> {
let rendered = Index {};

View File

@ -32,3 +32,9 @@
margin-left: 5px;
}
}
input[type=text],
input[type=password],
input[type=email] {
padding: 4px 6px;
border-radius: 6px;
}

View File

@ -29,7 +29,7 @@
</li>
</ul>
<p>
<label class="fancycheckbox">
<label>
<input type="checkbox" name="named">
</label>
<label for="bfile-formupload-file-name">
@ -42,6 +42,15 @@
<input style="max-width:100px" id='bfile-formupload-file-name' type="text" name="filename" placeholder="file.txt"></input>
</span>
</p>
<p>
<label>
<input type="checkbox" name="passworded">
</label>
<label>
I want to add a password to the file:
<input type="password" name="password" style="max-width:90px">
</label>
</p>
<p>
<input type="file" name="file" id="bfile-formupload-file" style="display: none" />
<label for="bfile-formupload-file">