react-rust-postgres: create simple server

Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com>
This commit is contained in:
Jérémie Drouet 2020-03-23 14:00:43 +01:00
parent 4478c5c142
commit bdd0256bfc
6 changed files with 91 additions and 0 deletions

View File

@ -0,0 +1,2 @@
target
Cargo.lock

View File

@ -0,0 +1,2 @@
target
Cargo.lock

View 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"]

View 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" ]

View 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();
}

View 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: {}