Skip to content

Commit

Permalink
update Status code for post and delete fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Matisse Chenavas committed Jun 26, 2024
1 parent c045ebf commit a8744a8
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 16 deletions.
14 changes: 9 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
FROM debian:bullseye-slim
RUN apt-get update
RUN apt-get install -y curl
RUN curl -fsSL https://deb.nodesource.com/setup_20.x -o nodesource_setup.sh && bash nodesource_setup.sh
RUN apt-get install -y make clang python3 php-cgi libpthread-stubs0-dev nodejs
FROM alpine:3.20

RUN apk add --no-cache make nodejs clang python3 php82-cgi inotify-tools curl
RUN ln -sf /usr/bin/clang++ /usr/bin/c++ && mkdir -p /var/www/html \
&& ln -sf /usr/bin/php-cgi82 /usr/bin/php-cgi

RUN mkdir -p /var/www/html

ARG UID
ARG GID
RUN export MY_UID=${UID} && export MY_GID=${GID}

WORKDIR /app

COPY ./run.sh .
Expand Down
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# By: mchenava <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/12/15 15:51:13 by agaley #+# #+# #
# Updated: 2024/06/26 10:53:29 by mchenava ### ########.fr #
# Updated: 2024/06/26 15:07:45 by mchenava ### ########.fr #
# #
# **************************************************************************** #

Expand Down Expand Up @@ -50,7 +50,14 @@ DEBUG_DEPS = $(patsubst $(SRC_DIR)/%.cpp, $(DEBUG_OBJ_DIR)/%.d, $(SRC))

VPATH = $(SRC_DIR)

all: $(NAME)
all: $(NAME) setup

setup:
NUM=1; \
for file in /var/www/html/static_templates/*; do \
ln -s $$file /var/www/html/static_templates/static$$NUM; \
NUM=$$((NUM + 1)); \
done

$(NAME): $(OBJ) update_gitignore
$(CXX) $(CXXFLAGS) $(OBJ) -lpthread -o $(NAME)
Expand Down
100 changes: 98 additions & 2 deletions default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,105 @@ server {
}

server {
listen 8080;
listen 8081;
server_name static.1.fr;
root /var/www/html/static_templates/Animated\ Landing\ Page\ Website\ Template;
root /var/www/html/static_templates/static1;
index index.html;

location / {
index index.html;
limit_except GET { deny all; }
}

location /css/ {
autoindex on;
limit_except GET { deny all; }
}

location /js/ {
autoindex on;
limit_except GET { deny all; }
}

location /scss/ {
autoindex on;
limit_except GET { deny all; }
}

location /assets/ {
autoindex on;
limit_except GET { deny all; }
}
}

server {
listen 8082;
server_name static.2.fr;
root /var/www/html/static_templates/static2;
index index.html;

location / {
index index.html;
limit_except GET { deny all; }
}

location /css/ {
autoindex on;
limit_except GET { deny all; }
}

location /js/ {
autoindex on;
limit_except GET { deny all; }
}

location /scss/ {
autoindex on;
limit_except GET { deny all; }
}

location /assets/ {
autoindex on;
limit_except GET { deny all; }
}
}

server {
listen 8083;
server_name static.3.fr;
root /var/www/html/static_templates/static3;
index index.html;

location / {
index index.html;
limit_except GET { deny all; }
}

location /css/ {
autoindex on;
limit_except GET { deny all; }
}

location /js/ {
autoindex on;
limit_except GET { deny all; }
}

location /scss/ {
autoindex on;
limit_except GET { deny all; }
}

location /assets/ {
autoindex on;
limit_except GET { deny all; }
}
}

server {
listen 8084;
server_name static.4.fr;
root /var/www/html/static_templates/static4;
index index.html;

location / {
Expand Down
12 changes: 5 additions & 7 deletions src/ConnectionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* ConnectionHandler.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mchenava < mchenava@student.42lyon.fr> +#+ +:+ +#+ */
/* By: mchenava <mchenava@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/30 16:11:21 by agaley #+# #+# */
/* Updated: 2024/06/25 17:49:36 by mchenava ### ########.fr */
/* Updated: 2024/06/26 11:30:59 by mchenava ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -277,15 +277,13 @@ void ConnectionHandler::processConnection() {
std::string status = Utils::to_string(_response->getStatusCode());
std::string contentLength =
_response->getHeaders().find("Content-Length")->second;
_log.info("CONNECTION_HANDLER: Connection closed, client socket: " +
Utils::to_string(_clientSocket));
_log.info("Request : " + host + " - " + method + " " + uri + " " +
protocol);
_log.info("Response : " + status + " " + contentLength);
_log.info("Response : " + status + " sent " + contentLength + " bytes");
epoll_ctl(_epollSocket, EPOLL_CTL_DEL, _clientSocket, NULL);
close(_clientSocket);
std::clock_t end = std::clock(); // Timestamp de fin
double duration = static_cast<double>(end - start) / CLOCKS_PER_SEC; // Calcul de la durée
std::clock_t end = std::clock();
double duration = static_cast<double>(end - start) / CLOCKS_PER_SEC;
if (duration > 0.005) {
_log.warning("CONNECTION_HANDLER: =================================Processing time: " + Utils::to_string(duration) + " seconds");
}
Expand Down

0 comments on commit a8744a8

Please sign in to comment.