Skip to content

Commit

Permalink
ref: bash && remove colors
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroFnseca committed Aug 29, 2023
1 parent bd6a4a8 commit d0e79ba
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 35 deletions.
Binary file modified bin/main
Binary file not shown.
14 changes: 14 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions docker_run.sh
Original file line number Diff line number Diff line change
@@ -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
28 changes: 23 additions & 5 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -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
# 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
7 changes: 7 additions & 0 deletions main_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

./build.sh

echo "Executando o programa..."

./bin/main
13 changes: 13 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
14 changes: 0 additions & 14 deletions run.sh

This file was deleted.

16 changes: 1 addition & 15 deletions src/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,5 @@
#include <string.h>

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);
}
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit d0e79ba

Please sign in to comment.