Skip to content

Commit

Permalink
fix: autoindex logic #225 (#227)
Browse files Browse the repository at this point in the history
* fix: change autoindex logic

* chore: remove unneccessary file
  • Loading branch information
chanhihi authored Aug 1, 2023
1 parent 4e3315f commit 0a8d60d
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ server {
}

location /directory {
root /tests/html/;
root /tests/;
allow_method GET;
autoindex on;
}
Expand Down
2 changes: 1 addition & 1 deletion srcs/clients/method/include/GET.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define STYLE \
"<style> body { padding: 2rem; line-height : " \
"2.5rem; } h1 { margin-bottom : 2rem; } a { margin-top: " \
"0.5rem; " \
"0.3rem; " \
"margin-bottom: 0.5rem; display: block;}</style></head>\r\n "
#define HTML_BODY_END "\r\n</body>\r\n</html>"

Expand Down
4 changes: 2 additions & 2 deletions srcs/clients/method/src/GET.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ void GET::getPublicEndpoint(RequestDts& dts, IResponse& response) {
matchedIndex = (*dts.matchedLocation)->getIndex();
pathIndex = path + (path[path.size() - 1] == '/' ? matchedIndex
: "/" + matchedIndex);
autoindex = (*dts.matchedLocation)->getAutoindex();
}
autoindex = (*dts.matchedLocation)->getAutoindex();
if (checkFile(path)) {
*dts.statusCode = E_200_OK;
prepareBody(path, response);
Expand Down Expand Up @@ -218,7 +218,7 @@ std::string GET::generateHTML(const std::string& path,
std::string html = HTML_HEAD_TITLE(path) + STYLE + HTML_BODY(path);
for (std::vector<std::string>::const_iterator it = files.begin();
it != files.end(); ++it) {
html += "<a href=\"" + *it + "\" style =\"font-size:1.5rem;\">" +
html += "<a href=\"" + *it + "\" style =\"font-size:1rem;\">" +
((*it)[it->size() - 1] == '/' ? "📁 " : "📄 ") + *it + "</a>";
}
html += HTML_BODY_END;
Expand Down
Empty file removed tests/file1
Empty file.
Empty file removed tests/file2.cpp
Empty file.
Empty file removed tests/file3.hpp
Empty file.

0 comments on commit 0a8d60d

Please sign in to comment.