added deployment via docker compose
This commit is contained in:
@@ -1 +1,2 @@
|
||||
DATABASE_URL="postgresql://chatapp:chatapp@100.118.108.58:5432/chatapp"
|
||||
ROCKET_SECRET_KEY="fCHCI6x/uItqldCJTdbruqQvXQXAeH/+vGtXmu3Hv6A="
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
/target
|
||||
@@ -0,0 +1,47 @@
|
||||
FROM docker.io/rust:1-slim-bookworm AS build
|
||||
|
||||
## cargo package name: customize here or provide via --build-arg
|
||||
ARG pkg=backend
|
||||
ARG DATABASE_URL
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
COPY .cargo .cargo
|
||||
COPY cdn cdn
|
||||
COPY src src
|
||||
COPY Cargo.toml Cargo.toml
|
||||
COPY Rocket.toml Rocket.toml
|
||||
COPY static static
|
||||
COPY templates templates
|
||||
|
||||
RUN apt-get update && apt-get install -y libssl-dev pkg-config
|
||||
|
||||
RUN --mount=type=cache,target=/build/target \
|
||||
--mount=type=cache,target=/usr/local/cargo/registry \
|
||||
--mount=type=cache,target=/usr/local/cargo/git \
|
||||
set -eux; \
|
||||
cargo build --release; \
|
||||
objcopy --compress-debug-sections target/release/$pkg ./main
|
||||
|
||||
################################################################################
|
||||
|
||||
FROM docker.io/debian:bookworm-slim
|
||||
|
||||
RUN apt-get update && apt-get install -y libssl-dev pkg-config
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
## copy the main binary
|
||||
COPY --from=build /build/main ./
|
||||
|
||||
## copy runtime assets which may or may not exist
|
||||
COPY --from=build /build/Rocket.toml ./Rocket.toml
|
||||
COPY --from=build /build/static ./static
|
||||
COPY --from=build /build/cdn ./cdn
|
||||
COPY --from=build /build/template[s] ./templates
|
||||
|
||||
## ensure the container listens globally on port 8000
|
||||
ENV ROCKET_ADDRESS=0.0.0.0
|
||||
ENV ROCKET_PORT=8000
|
||||
|
||||
CMD ./main
|
||||
@@ -1,6 +1,12 @@
|
||||
[debug]
|
||||
secret_key = "yYhvCGnRh/TrcHtB8sZqCFifrVmJxoKFLBYw/WWBZeU="
|
||||
address = "127.0.0.1"
|
||||
port = 8000
|
||||
|
||||
[default.databases.postgres_db]
|
||||
url = "postgresql://chatapp:chatapp@100.118.108.58:5432/chatapp"
|
||||
|
||||
[default] # run inside a docker container or pod
|
||||
secret_key = "fCHCI6x/uItqldCJTdbruqQvXQXAeH/+vGtXmu3Hv6A="
|
||||
address = "0.0.0.0"
|
||||
port = 8082
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@ pub async fn mfa_page(session: Session) -> Template {
|
||||
}
|
||||
|
||||
#[get("/api/totp.jpg")]
|
||||
pub async fn gen_totp(s: Session) -> Option<QrCodeImage> {
|
||||
pub async fn get_totp(s: Session) -> Option<QrCodeImage> {
|
||||
let totp = TOTP::new(
|
||||
Algorithm::SHA1,
|
||||
6,
|
||||
|
||||
+19
-6
@@ -2,7 +2,7 @@
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
|
||||
use rocket::fs::FileServer;
|
||||
use rocket::fs::{FileServer, NamedFile};
|
||||
use rocket::http::Method;
|
||||
use rocket::serde::json::Json;
|
||||
use rocket::{Build, Rocket};
|
||||
@@ -66,16 +66,29 @@ fn rocket() -> Rocket<Build> {
|
||||
.mount(
|
||||
"/",
|
||||
routes![
|
||||
users,
|
||||
username_for_id,
|
||||
favicon,
|
||||
messages::chat_page,
|
||||
auth::signup_page,
|
||||
auth::login_page,
|
||||
auth::mfa_page,
|
||||
],
|
||||
)
|
||||
.mount(
|
||||
"/api",
|
||||
routes![
|
||||
messages::get_messages,
|
||||
messages::post_message,
|
||||
messages::event_stream,
|
||||
users,
|
||||
username_for_id,
|
||||
auth::signup,
|
||||
auth::signup_page,
|
||||
auth::login_page,
|
||||
auth::login
|
||||
auth::login,
|
||||
auth::get_totp,
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
#[get("/favicon.ico")]
|
||||
async fn favicon() -> NamedFile {
|
||||
NamedFile::open("static/favicon.ico").await.unwrap()
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
max-width: 100vw;
|
||||
min-width: 100vw;
|
||||
margin: 0 0;
|
||||
background: #121212;
|
||||
position: relative;
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
@@ -165,7 +165,7 @@
|
||||
function sendMessage() {
|
||||
const message = input.value.trim();
|
||||
if (message) {
|
||||
fetch("http://localhost:8000/chat", {
|
||||
fetch("/api/chat", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
user_id: user_id,
|
||||
@@ -189,11 +189,11 @@
|
||||
|
||||
async function loadData() {
|
||||
try {
|
||||
const userIds = await fetch("http://localhost:8000/users/")
|
||||
const userIds = await fetch("/api/users/")
|
||||
.then(r => r.json());
|
||||
|
||||
const userPromises = userIds.map(userId =>
|
||||
fetch(`http://localhost:8000/users/${userId}`)
|
||||
fetch(`/api/users/${userId}`)
|
||||
.then(r => r.text())
|
||||
.then(username => ({ userId, username }))
|
||||
);
|
||||
@@ -206,7 +206,8 @@
|
||||
|
||||
console.log('Users loaded:', users);
|
||||
|
||||
const messageSource = new EventSource("http://localhost:8000/events");
|
||||
const messageSource = new EventSource("/api/events");
|
||||
messageSource.onopen = () => messagesContainer.innerHTML = '';
|
||||
messageSource.onmessage = (event) => insertMessage(JSON.parse(event.data));
|
||||
messageSource.onerror = (error) => {
|
||||
console.error('EventSource error:', error);
|
||||
|
||||
@@ -109,7 +109,7 @@
|
||||
try {
|
||||
// Replace with your actual backend endpoint
|
||||
const response = await fetch(
|
||||
"http://localhost:8000/login",
|
||||
"/api/login",
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
||||
@@ -225,7 +225,7 @@
|
||||
try {
|
||||
// Replace with your actual backend endpoint
|
||||
const response = await fetch(
|
||||
"http://localhost:8000/signup",
|
||||
"/api/signup",
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user