react-rust-postgres: create simple server

Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com>
master
Jérémie Drouet 5 years ago
parent 4478c5c142
commit bdd0256bfc

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

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

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

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

@ -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…
Cancel
Save