diff --git a/.gitignore b/.gitignore index 8668e2b..e968bf6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ * -!srcs/*/ +!srcs/ +!srcs/load/ +!srcs/json/ !srcs/*/*.cpp !srcs/*/*.hpp !srcs/*.hpp diff --git a/Makefile b/Makefile index a618b2a..76b6b63 100644 --- a/Makefile +++ b/Makefile @@ -2,13 +2,13 @@ NAME= server SRCS= srcs/webserv.cpp srcs/tools.cpp OBJS= $(SRCS:.cpp=.o) CXX=c++ -CXXFLAGS= -Werror -Wextra -Wall -std=c++98 +CXXFLAGS= -g -Werror -Wextra -Wall -std=c++98 all : $(NAME) $(NAME): $(OBJS) - $(CXX) $(OBJS) -o $(NAME) + $(CXX) -g -fsanitize=address $(OBJS) -o $(NAME) clean: rm -rf $(OBJS) diff --git a/default.json b/default.json new file mode 100644 index 0000000..8e524d7 --- /dev/null +++ b/default.json @@ -0,0 +1,30 @@ +{ + "max_clients": 30, + "root_folder": "./www", + "servers": [ + { + "server_name": "localhost", + "listens": ["15000", "[::]:88"], + "return": "301 https://$host$uri" + }, + { + "server_name": "localhost", + "listens": ["150005", "[::]:88"], + "root": "./public", + "index": ["index.html"], + "locations": + { + "/docs": + { + "root": "./documents", + "autoindex": true + }, + "/img": + { + "root": "./images" + } + + } + } + ] +} diff --git a/srcs/load/Env.hpp b/srcs/load/Env.hpp index 5753018..3816b1b 100644 --- a/srcs/load/Env.hpp +++ b/srcs/load/Env.hpp @@ -6,18 +6,17 @@ class Env { std::vector _servers; public: Env(JSONNode *conf) { - conf->obj()["max_clients"]->nbr(); JSONList servers = conf->obj()["servers"]->lst(); int i = 0; string th[8]= {"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eigth"}; for (std::vector::iterator it = servers.begin(); it < servers.end(); it++) { - Server *server = new Server(*it); - delete *it; - server->launch(); - cout << th[i] << " server launched."; + Server *server = new Server(*it); + server->launch(); + //delete *it; + cout << th[i] << " server launched.\n"; i++; } - delete conf; + //delete conf; } }; diff --git a/srcs/load/Server.hpp b/srcs/load/Server.hpp index a85a04f..126e0d8 100644 --- a/srcs/load/Server.hpp +++ b/srcs/load/Server.hpp @@ -9,11 +9,17 @@ class Server { public: Server(JSONNode *server) { + _port = 80; JSONObject datas = server->obj(); - _name = datas["server_name"]->str(); - JSONList listens = datas["listens"]->lst(); - for (JSONList::iterator i = listens.begin(); i < listens.end(); i++) - _listens.push_back((*i)->str()); + if (datas["server_name"]) + _name = datas["server_name"]->str(); + if (datas["listens"]) { + JSONList listens = datas["listens"]->lst(); + for (JSONList::iterator i = listens.begin(); i < listens.end(); i++) + _listens.push_back((*i)->str()); + _port = std::atoi(_listens.front().c_str()); + + } //_routes["default"] = new Route(datas["root"], datas["return"], datas["index"], datas["autoindex"]); } void launch() {