mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-06-25 09:33:36 +02:00
「✨」 feat: changed a few things to be more production ready
This commit is contained in:
@ -80,7 +80,7 @@ Route::Route(toml::ANode *table)
|
||||
if (val != not_nullptr)
|
||||
_dirlist = *static_cast<bool *>(val);
|
||||
else
|
||||
_dirlist = true;
|
||||
_dirlist = false;
|
||||
/* val = accessValue("cookies", toml::BOOL, _table, _log); */
|
||||
/* if (val != not_nullptr) */
|
||||
/* _cookies = *static_cast<bool *>(val); */
|
||||
|
16
src/help.cpp
16
src/help.cpp
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/10 13:08:36 by adjoly #+# #+# */
|
||||
/* Updated: 2025/05/08 11:21:10 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/05/08 11:58:13 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -29,18 +29,18 @@ void _printHelp(void) {
|
||||
std::cout << "-------------------------------------" << std::endl;
|
||||
}
|
||||
|
||||
void _generateConf(void) {
|
||||
void _generateConf(const std::string path) {
|
||||
webserv::Logger _log;
|
||||
if (access(SAMPLE_CONF_PATH, F_OK) == 0) {
|
||||
if (access(path.c_str(), F_OK) == 0) {
|
||||
_log.warn(std::string(SAMPLE_CONF_PATH) + " already exist, aborting");
|
||||
} else {
|
||||
std::stringstream str;
|
||||
str << "generating config into " << SAMPLE_CONF_PATH << "...";
|
||||
_log.info(str.str());
|
||||
std::ofstream file(SAMPLE_CONF_PATH);
|
||||
std::ofstream file(path.c_str());
|
||||
if (file.is_open()) {
|
||||
file << "[server]\nhost = \"0.0.0.0\"\nport = "
|
||||
"80\n\n[server.location./]\ndirlist = false\n";
|
||||
"80\n\n[server.location./]\n";
|
||||
file.close();
|
||||
_log.info("config file successfully generated");
|
||||
} else {
|
||||
@ -58,15 +58,15 @@ void _printVersion(void) {
|
||||
|
||||
bool help(int ac, char **av) {
|
||||
if (ac < 2) {
|
||||
_printHelp();
|
||||
return true;
|
||||
_generateConf(SAMPLE_CONF_PATH);
|
||||
return false;
|
||||
}
|
||||
std::string option = av[1];
|
||||
if (option == "--help" || option == "-v") {
|
||||
_printHelp();
|
||||
return true;
|
||||
} else if (option == "--generate" || option == "-g") {
|
||||
_generateConf();
|
||||
_generateConf(SAMPLE_CONF_PATH);
|
||||
return true;
|
||||
} else if (option == "--version" || option == "-v") {
|
||||
_printVersion();
|
||||
|
18
src/main.cpp
18
src/main.cpp
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/03 15:45:07 by mmoussou #+# #+# */
|
||||
/* Updated: 2025/05/06 19:20:55 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/05/08 12:00:41 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -45,7 +45,14 @@ int main(int ac, char **av) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
log.info("Starting server...");
|
||||
if (access(av[1], F_OK) < 0) {
|
||||
if (ac < 2) {
|
||||
if (access(SAMPLE_CONF_PATH, F_OK) < 0) {
|
||||
std::stringstream str;
|
||||
str << "File : " << SAMPLE_CONF_PATH << " could not be opened";
|
||||
log.error(str.str());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
} else if (access(av[1], F_OK) < 0) {
|
||||
std::stringstream str;
|
||||
str << "File : " << av[1] << " could not be opened";
|
||||
log.error(str.str());
|
||||
@ -55,7 +62,12 @@ int main(int ac, char **av) {
|
||||
_log = not_nullptr;
|
||||
config::Config *conf;
|
||||
try {
|
||||
std::string str = av[1];
|
||||
std::string str;
|
||||
if (ac < 2) {
|
||||
str = SAMPLE_CONF_PATH;
|
||||
} else {
|
||||
str = av[1];
|
||||
}
|
||||
conf = new config::Config(str);
|
||||
} catch (std::exception &) {
|
||||
if (_log != not_nullptr)
|
||||
|
Reference in New Issue
Block a user