Browse Source

save 22-11-4-2

test
nicolas-arnaud 2 years ago
parent
commit
c119d34186
  1. 4
      .gitignore
  2. 4
      Makefile
  3. 30
      default.json
  4. 11
      srcs/load/Env.hpp
  5. 14
      srcs/load/Server.hpp

4
.gitignore

@ -1,5 +1,7 @@
*
!srcs/*/
!srcs/
!srcs/load/
!srcs/json/
!srcs/*/*.cpp
!srcs/*/*.hpp
!srcs/*.hpp

4
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)

30
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"
}
}
}
]
}

11
srcs/load/Env.hpp

@ -6,18 +6,17 @@ class Env {
std::vector<Server> _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<JSONNode *>::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;
}
};

14
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() {

Loading…
Cancel
Save