-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackend.txt
More file actions
81 lines (49 loc) · 3.07 KB
/
Copy pathbackend.txt
File metadata and controls
81 lines (49 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
Fonte: https://mongoose.ws/documentation/
Referência video (inglês): https://www.youtube.com/watch?v=2Hq1wc1AzCY
-------------------------------------------------------------------------------
1o - Primeiro foi necessário instalar a biblioteca para subir servidor web: Mongoose;
1o - Não existe no repositório Ubuntu mais recente, então doi necessário baixar
direto da fonte e instalar manualmente: https://github.com/cesanta/mongoose/releases/tag/7.9
- Site Oficial: https://mongoose.ws/
2o - Após descompactado, entramos na pasta gerada e executamos:
- $ sudo make install (Instala as dependencias)
- $ sudo make linux-libs
- $ make
3o - Aqui o servidor ja fica running, para testar: http://0.0.0.0:8000
-------------------------------------------------------------------------------
2o - Entendendo os arquivos:
- Existem exemplos de implementações para http-server em: /webserver/examples/http-server
- O Arquivo que devemos configurar é o Makefile, que é o arquivo que possuem os parâmetros
do make: PORÉM esse exemplo suporta apenas Windows!
---------------------------------------------------------------------------
[Makefile] content:
PROG ?= example
ROOT ?= $(realpath $(CURDIR)/../..)
DEFS ?= -DMG_ENABLE_LINES=1 -DMG_ENABLE_IPV6=1 -DMG_ENABLE_SSI=1 -DMG_HTTP_DIRLIST_TIME=1
CFLAGS ?= -I../.. -W -Wall $(DEFS) $(EXTRA)
VCFLAGS = /nologo /W3 /O2 /I../.. $(DEFS) $(EXTRA) /link /incremental:no /machine:IX86
VC98 = docker run -it --rm -e Tmp=. -v $(ROOT):$(ROOT) -w $(CURDIR) mdashnet/vc98
all: $(PROG)
$(RUN) ./$(PROG) $(ARGS)
$(PROG): main.c Makefile
$(CC) ../../mongoose.c main.c -I../.. $(CFLAGS) -o $@
mongoose.exe: main.c
$(VC98) wine cl ../../mongoose.c main.c $(VCFLAGS) ws2_32.lib /out:$@
mingw:
gcc ../../mongoose.c main.c -I../.. -W -Wall $(DEFS) -D_POSIX_C_SOURCE=200000L -lws2_32 -o mongoose.exe
clean:
rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb mongoose mongoose_* mongoose.*
---------------------------------------------------------------------------
- Quando executamos $ make mingw o comando que será executado é o:
$ gcc ../../mongoose.c main.c -I../.. -W -Wall $(DEFS) -D_POSIX_C_SOURCE=200000L -lws2_32 -o mongoose.exe
- No meu caso eu estou utilizando Linux, e esse exemplo não suporta diferente do Makefile principal.
-------------------------------------------------------------------------------
3o - Implementando a função para o método HTTP Post: examples/webui-rest
- Ja existe template pronto para API REST: https://mongoose.ws/documentation/tutorials/webui-rest/
- Como trabalhar com Json no mongoose: https://mongoose.ws/documentation/#using-json
- Starting/Running:
$ cd examples/webui-rest
$ make clean all
- index.html do front: examples/webui-rest/web-root/index.html
- Implementações dos metodos GET e POST: examples/webui-rest/main.c
-------------------------------------------------------------------------------