react-rust-postgres: create simple server
Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com>
This commit is contained in:
parent
4478c5c142
commit
bdd0256bfc
2
react-rust-postgres/backend/.dockerignore
Normal file
2
react-rust-postgres/backend/.dockerignore
Normal file
@ -0,0 +1,2 @@
|
||||
target
|
||||
Cargo.lock
|
2
react-rust-postgres/backend/.gitignore
vendored
Normal file
2
react-rust-postgres/backend/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
target
|
||||
Cargo.lock
|
18
react-rust-postgres/backend/Cargo.toml
Normal file
18
react-rust-postgres/backend/Cargo.toml
Normal file
@ -0,0 +1,18 @@
|
||||
[package]
|
||||
name = "react-rust-postgres"
|
||||
version = "0.1.0"
|
||||
authors = ["Jérémie Drouet <jeremie.drouet@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rocket = "0.4.4"
|
||||
serde = "1.0"
|
||||
serde_json = "1.0"
|
||||
serde_derive = "1.0"
|
||||
|
||||
[dependencies.rocket_contrib]
|
||||
version = "0.4.4"
|
||||
default-features = false
|
||||
features = ["json"]
|
28
react-rust-postgres/backend/Dockerfile
Normal file
28
react-rust-postgres/backend/Dockerfile
Normal file
@ -0,0 +1,28 @@
|
||||
FROM jdrouet/rust-nightly:buster-slim AS base
|
||||
|
||||
ENV USER=root
|
||||
ENV ROCKET_ADDRESS=0.0.0.0
|
||||
|
||||
WORKDIR /code
|
||||
RUN cargo init
|
||||
COPY Cargo.toml /code/Cargo.toml
|
||||
RUN cargo fetch
|
||||
COPY . /code
|
||||
|
||||
FROM base AS development
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
CMD [ "cargo", "run", "--offline" ]
|
||||
|
||||
FROM base AS builder
|
||||
|
||||
RUN cargo build --release --offline
|
||||
|
||||
FROM debian:buster-slim
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
COPY --from=builder /code/target/release/react-rust-postgres /react-rust-postgres
|
||||
|
||||
CMD [ "/react-rust-postgres" ]
|
25
react-rust-postgres/backend/src/main.rs
Normal file
25
react-rust-postgres/backend/src/main.rs
Normal file
@ -0,0 +1,25 @@
|
||||
#![feature(proc_macro_hygiene, decl_macro)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
extern crate rocket_contrib;
|
||||
|
||||
use rocket_contrib::json::Json;
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct HelloMessage {
|
||||
message: String,
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
fn index() -> Json<HelloMessage> {
|
||||
Json(HelloMessage {
|
||||
message: String::from("Hello, world"),
|
||||
})
|
||||
}
|
||||
|
||||
fn main() {
|
||||
rocket::ignite().mount("/", routes![index]).launch();
|
||||
}
|
16
react-rust-postgres/docker-compose.yaml
Normal file
16
react-rust-postgres/docker-compose.yaml
Normal file
@ -0,0 +1,16 @@
|
||||
version: "3.7"
|
||||
services:
|
||||
backend:
|
||||
build:
|
||||
context: backend
|
||||
target: development
|
||||
networks:
|
||||
- server-side
|
||||
volumes:
|
||||
- ./backend/src:/code/src:ro
|
||||
- backend-cache:/code/target
|
||||
networks:
|
||||
client-side: {}
|
||||
server-side: {}
|
||||
volumes:
|
||||
backend-cache: {}
|
Loading…
Reference in New Issue
Block a user