Skip to content

Commit 04957c0

Browse files
committed
1 parent 96e9ec0 commit 04957c0

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,24 @@ svr.listen_after_bind();
5050
### Static File Server
5151

5252
```cpp
53-
svr.set_base_dir("./www"); // This is same as `svr.set_base_dir("./www", "/")`;
53+
auto ret = svr.set_base_dir("./www"); // This is same as `svr.set_base_dir("./www", "/")`;
54+
if (!ret) {
55+
// The specified base directory doesn't exist...
56+
}
5457

55-
// User defined file extension and MIME type mappings
56-
svr.set_file_extension_and_mimetype_mapping("cc", "text/x-c");
57-
svr.set_file_extension_and_mimetype_mapping("cpp", "text/x-c");
58-
svr.set_file_extension_and_mimetype_mapping("hh", "text/x-h");
59-
```
58+
// Mount /public to ./www directory
59+
ret = svr.set_base_dir("./www", "/public");
6060

61-
```cpp
62-
svr.set_base_dir("./www", "/public");
61+
// Mount /public to ./www1 and ./www2 directories
62+
ret = svr.set_base_dir("./www1", "/public"); // 1st order to search
63+
ret = svr.set_base_dir("./www2", "/public"); // 2nd order to search
6364
```
6465

6566
```cpp
66-
svr.set_base_dir("./www1", "/public"); // 1st order
67-
svr.set_base_dir("./www2", "/public"); // 2nd order
67+
// User defined file extension and MIME type mappings
68+
svr.set_file_extension_and_mimetype_mapping("cc", "text/x-c");
69+
svr.set_file_extension_and_mimetype_mapping("cpp", "text/x-c");
70+
svr.set_file_extension_and_mimetype_mapping("hh", "text/x-h");
6871
```
6972

7073
The followings are built-in mappings:

example/simplesvr.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ int main(int argc, const char **argv) {
122122
auto base_dir = "./";
123123
if (argc > 2) { base_dir = argv[2]; }
124124

125-
svr.set_base_dir(base_dir);
125+
if (!svr.set_base_dir(base_dir)) {
126+
cout << "The specified base directory doesn't exist...";
127+
return 1;
128+
}
126129

127130
cout << "The server started at port " << port << "...";
128131

0 commit comments

Comments
 (0)