diff --git a/bin/main b/bin/main index d79340a..646dce5 100755 Binary files a/bin/main and b/bin/main differ diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..77d24b8 --- /dev/null +++ b/build.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Cria a pasta bin se não existir +mkdir -p bin + +# Compila o código da pasta src usando gcc e libmicrohttpd, e coloca o executável na pasta bin +gcc -o bin/main src/main.c -lmicrohttpd + +# Verifica se a compilação foi bem-sucedida +if [ $? -eq 0 ]; then + echo "Compilação bem-sucedida." +else + echo "Erro durante a compilação." +fi diff --git a/docker_run.sh b/docker_run.sh new file mode 100755 index 0000000..cce8e23 --- /dev/null +++ b/docker_run.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Nome do contêiner +CONTAINER_NAME="rest-api-c" + +# Remove o contêiner existente com o mesmo nome +docker rm -f "$CONTAINER_NAME" >/dev/null 2>&1 + +# Constrói a imagem do Docker a partir do Dockerfile +docker build -t rest-api-c . + +# Executa o contêiner, expondo a porta 8080 e atribuindo o nome "rest-api-c" +docker run -d -p 8080:80 --name "$CONTAINER_NAME" rest-api-c diff --git a/dockerfile b/dockerfile index fbfb31b..adde841 100644 --- a/dockerfile +++ b/dockerfile @@ -1,6 +1,24 @@ -FROM ubuntu:latest +# Use uma imagem de base com suporte para compilação C +FROM gcc:latest -RUN apt-get update && apt-get install -y \ - libmicrohttpd-dev \ - gcc \ - make \ No newline at end of file +# Instale as dependências necessárias +RUN apt-get update && \ + apt-get install -y libmicrohttpd-dev make nginx + +RUN mkdir -p /app + +WORKDIR /app + +COPY . /app + +RUN ./build.sh + +COPY nginx.conf /etc/nginx/nginx.conf + +EXPOSE 80 + +CMD nginx -g "daemon off;" + +RUN ./bin/main + +# Rever execução do ./bin/main \ No newline at end of file diff --git a/main_run.sh b/main_run.sh new file mode 100755 index 0000000..01c0e74 --- /dev/null +++ b/main_run.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +./build.sh + +echo "Executando o programa..." + +./bin/main \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..466d820 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,13 @@ +worker_processes 1; +events { worker_connections 1024; } + +http { + server { + listen 80; + server_name localhost; + + location / { + proxy_pass http://127.0.0.1:8080; + } + } +} diff --git a/run.sh b/run.sh deleted file mode 100755 index 25e4627..0000000 --- a/run.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -echo -e "\n\033[0;33mCompiling...\033[0m\n" - -make - -if [ $? -ne 0 ]; then - echo -e "\n\033[0;31mCompilation failed!\033[0m\n" - exit 1 -fi - -echo -e "\n\033[0;32mCompilation successful!\033[0m\n" - -./bin/main \ No newline at end of file diff --git a/src/logger.h b/src/logger.h index 3099f6d..1ae3ab8 100644 --- a/src/logger.h +++ b/src/logger.h @@ -2,19 +2,5 @@ #include void log_api(const char *url, const char *method) { - char *color; - - if (strcmp(method, "GET") == 0) { - color = "\033[0;32m"; - } else if (strcmp(method, "POST") == 0) { - color = "\033[0;33m"; - } else if (strcmp(method, "PUT") == 0) { - color = "\033[0;34m"; - } else if (strcmp(method, "DELETE") == 0) { - color = "\033[0;35m"; - } else { - color = "\033[0;36m"; - } - - printf("%s[%s] %s -> %s\n", color, method, url); + printf("[%s] %s\n", method, url); } \ No newline at end of file diff --git a/src/main.c b/src/main.c index 4d61484..7a4e9c6 100644 --- a/src/main.c +++ b/src/main.c @@ -7,7 +7,7 @@ #define color_green "\033[0;32m" int main() { - printf("%sStart server on port %d\n", color_green, PORT); + printf("Starting server on port %d\n", PORT); struct MHD_Daemon *daemon;