Moved backend into backend folder

This commit is contained in:
Chris Jean-Marie 2024-09-20 00:15:32 +00:00
parent d641970187
commit bfa9433350
63 changed files with 43 additions and 102 deletions

2
.cargo/config.toml Normal file
View File

@ -0,0 +1,2 @@
[build]
rustflags = ["-C", "link-arg=-fuse-ld=lld"]

View File

@ -1,13 +1,7 @@
# [Choice] Debian OS version (use bullseye on local arm64/Apple Silicon): buster, bullseye FROM mcr.microsoft.com/devcontainers/rust:1-1-bookworm
ARG VARIANT="bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/rust:0-${VARIANT}
# Include lld linker to improve build times either by using environment variable # Include lld linker to improve build times either by using environment variable
# RUSTFLAGS="-C link-arg=-fuse-ld=lld" or with Cargo's configuration file (i.e see .cargo/config.toml). # RUSTFLAGS="-C link-arg=-fuse-ld=lld" or with Cargo's configuration file (i.e see .cargo/config.toml).
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install clang lld \ && apt-get -y install clang lld \
&& apt-get autoremove -y && apt-get clean -y && apt-get autoremove -y && apt-get clean -y
# Add tools for wasm development
RUN rustup target add wasm32-unknown-unknown \
&& cargo install trunk cargo-edit cargo-watch

View File

@ -1,35 +1,18 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: // For format details, see https://aka.ms/devcontainer.json. For config options, see the
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/rust-postgres // README at: https://github.com/devcontainers/templates/tree/main/src/rust-postgres
{ {
"name": "Rust and PostgreSQL", "name": "Rust and PostgreSQL",
"dockerComposeFile": "docker-compose.yml", "dockerComposeFile": "docker-compose.yml",
"service": "app", "service": "app",
"workspaceFolder": "/workspace", "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"features": {
// Configure tool-specific properties. "ghcr.io/devcontainers/features/node:1": {},
"customizations": { "ghcr.io/lee-orr/rusty-dev-containers/cargo-watch:0": {},
// Configure properties specific to VS Code. "ghcr.io/lumenpink/devcontainer-features/wasm-pack:0": {}
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"lldb.executable": "/usr/bin/lldb",
// VS Code don't watch files under ./target
"files.watcherExclude": {
"**/target/**": true
},
"rust-analyzer.checkOnSave.command": "clippy"
}, },
// Add the IDs of extensions you want installed when the container is created. // Features to add to the dev container. More info: https://containers.dev/features.
"extensions": [ // "features": {},
"vadimcn.vscode-lldb",
"mutantdino.resourcemonitor",
"rust-lang.rust-analyzer",
"tamasfe.even-better-toml",
"serayuzgur.crates"
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally. // Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [5432], // "forwardPorts": [5432],
@ -37,9 +20,9 @@
// Use 'postCreateCommand' to run commands after the container is created. // Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "rustc --version", // "postCreateCommand": "rustc --version",
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. // Configure tool-specific properties.
"remoteUser": "vscode", // "customizations": {},
"features": {
"docker-in-docker": "latest" // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
} "remoteUser": "root"
} }

View File

@ -8,22 +8,12 @@ services:
build: build:
context: . context: .
dockerfile: Dockerfile dockerfile: Dockerfile
args:
# Use the VARIANT arg to pick a Debian OS version: buster, bullseye
# Use bullseye when on local on arm64/Apple Silicon.
VARIANT: bullseye
env_file: env_file:
# Ensure that the variables in .env match the same variables in devcontainer.json # Ensure that the variables in .env match the same variables in devcontainer.json
- .env - .env
# Security Opt and cap_add for C++ based debuggers to work.
# See `runArgs`: https://github.com/Microsoft/vscode-docs/blob/main/docs/remote/devcontainerjson-reference.md
# security_opt:
# - seccomp:unconfined
# cap_add:
# - SYS_PTRACE
volumes: volumes:
- ..:/workspace:cached - ../..:/workspaces:cached
# Overrides default command so things don't shut down after the process ends. # Overrides default command so things don't shut down after the process ends.
command: sleep infinity command: sleep infinity
@ -31,9 +21,6 @@ services:
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
network_mode: service:db network_mode: service:db
# Uncomment the next line to use a non-root user for all processes.
# user: vscode
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally. # Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
# (Adding the "ports" property to this file will not forward from a Codespace.) # (Adding the "ports" property to this file will not forward from a Codespace.)

2
.gitignore vendored
View File

@ -1 +1 @@
/target backend/target

View File

@ -1,18 +0,0 @@
FROM rust:1.59 as builder
RUN USER=root cargo new --bin jean-marie
WORKDIR /jean-marie
COPY ./Cargo.toml ./Cargo.toml
RUN cargo build --release
RUN rm src/*.rs
ADD . ./
RUN rm ./target/release/deps/jean_marie*
RUN cargo build --release
FROM debian:buster-slim
COPY --from=builder /jean-marie/target/release/jean-marie .
RUN mkdir -p /templates
CMD ["./jean-marie"]

View File

View File

@ -45,6 +45,13 @@ struct LoginTemplate {
name: String, name: String,
} }
#[derive(Template)]
#[template(path = "dashboard.html")]
struct DashboardTemplate {
logged_in: bool,
name: String,
}
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
struct User { struct User {
id: String, id: String,
@ -78,17 +85,10 @@ async fn main() {
// build our application with some routes // build our application with some routes
let app = Router::new() let app = Router::new()
.route("/assets", get_service(ServeDir::new("templates/assets")) .nest_service("/assets", ServeDir::new("templates/assets")
// .handle_error( .fallback(get_service(ServeDir::new("templates/assets"))))
// |error: std::io::Error| async move {
// (
// StatusCode::INTERNAL_SERVER_ERROR,
// format!("Unhandled internal error: {}", error),
// )
// },
// ),
)
.route("/", get(index)) .route("/", get(index))
.route("/dashboard", get(dashboard))
.route("/login", get(login)) .route("/login", get(login))
.route("/google_auth", get(google_auth)) .route("/google_auth", get(google_auth))
.route("/auth/google", get(google_authorized)) .route("/auth/google", get(google_authorized))
@ -125,3 +125,16 @@ async fn login(session: Session<SessionAnyPool>) -> impl IntoResponse {
let template = LoginTemplate { logged_in, name }; let template = LoginTemplate { logged_in, name };
HtmlTemplate(template) HtmlTemplate(template)
} }
async fn dashboard(session: Session<SessionAnyPool>) -> impl IntoResponse {
let logged_in = session.get("logged_in").unwrap_or(false);
let name = session.get("name").unwrap_or("".to_string());
session.set_store(true);
session.set("logged_in", logged_in);
session.set("name", &name);
let template = DashboardTemplate { logged_in, name };
HtmlTemplate(template)
}

View File

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

Before

Width:  |  Height:  |  Size: 306 KiB

After

Width:  |  Height:  |  Size: 306 KiB

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

Before

Width:  |  Height:  |  Size: 573 KiB

After

Width:  |  Height:  |  Size: 573 KiB

View File

Before

Width:  |  Height:  |  Size: 343 KiB

After

Width:  |  Height:  |  Size: 343 KiB

View File

Before

Width:  |  Height:  |  Size: 838 KiB

After

Width:  |  Height:  |  Size: 838 KiB

View File

@ -1,20 +0,0 @@
version: "3"
services:
jmqa:
image: silverfox68/jeanmarie:test
container_name: jmqa
environment:
- PUID=${PUID}
- PGID=${PGID}
- TZ=${TZ}
- GOOGLE_CLIENT_ID=735264084619-clsmvgdqdmum4rvrcj0kuk28k9agir1c.apps.googleusercontent.com
- GOOGLE_CLIENT_SECRET=L6uI7FQGoMJd-ay1HO_iGJ6M
- DISCORD_CLIENT_ID=956189108559036427
- DISCORD_CLIENT_SECRET=dx2DZxjDhVMCCnGX4xpz5MxSTgZ4lHBI
- FACEBOOK_CLIENT_ID=1529124327484248
- FACEBOOK_CLIENT_SECRET=189509b5eb907b3ce34b7e8459030f21
volumes:
- ../jean-marie/templates:/templates
ports:
- 40192:40192
restart: unless-stopped