Skip to content

Commit

Permalink
refactor: renamed runServer to run
Browse files Browse the repository at this point in the history
  • Loading branch information
araujo88 committed Mar 25, 2024
1 parent 73ee952 commit 4b5cf97
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ In `main.cpp` file:
int main(int argc, char *argv[])
{
tpt::Teapot server;
server.runServer();
server.run();
return 0;
}
```
Expand All @@ -49,7 +49,7 @@ To run in a different port:
int main(int argc, char *argv[])
{
tpt::Teapot server = tpt::Teapot(atoi(argv[1]));
server.runServer();
server.run();
return 0;
}
Expand All @@ -65,7 +65,7 @@ Optionally, the following arguments can be provided for the server instance:
int main(int argc, char *argv[])
{
tpt::Teapot server = tpt::Teapot(ip_address, port, max_connections, logging_type, static_files_dir);
server.runServer();
server.run();
return 0;
}

Expand All @@ -88,7 +88,7 @@ int main(int argc, char *argv[])
{
tpt::Teapot server;
server.serveFile("/example", "/example.html");
server.runServer();
server.run();
return 0;
}
```
Expand All @@ -102,7 +102,7 @@ int main(int argc, char *argv[])
{
tpt::Teapot server;
server.returnJSON("/test", "{\"name\": \"john\", \"surname\": \"doe\"}");
server.runServer();
server.run();
return 0;
}
```
Expand All @@ -116,7 +116,7 @@ int main(int argc, char *argv[])
{
tpt::Teapot server;
server.returnHTML("/example", "<html><h1>Example</h1></html>");
server.runServer();
server.run();
return 0;
}
```
Expand All @@ -134,12 +134,11 @@ int main(int argc, char *argv[])
tpt::Teapot server;
tpt::CORSMiddleware cors_middleware = tpt::CORSMiddleware("*", "*", "*", 86400, true);
server.addMiddleware(cors_middleware);
server.runServer();
server.run();
return 0;
}
```
For CORS middleware, the parameters are: `CORSMiddleware(allow_origins, allow_methods, allow_headers, max_age, allow_credentials)`.
You can create your own custom middleware by inherting from `IMiddleware` interface and implementing the `handle` method.
2 changes: 1 addition & 1 deletion include/teapot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace tpt
Teapot();
Teapot(unsigned int port);
Teapot(std::string ip_address, unsigned int port, unsigned int max_connections, logging logging_type, std::string static_files_dir);
void runServer();
void run();
void serveFile(std::string url, std::string file_path);
void returnHTML(std::string url, std::string html);
void returnHTML(std::string url, std::string html, unsigned int status_code);
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ int main(int argc, char *argv[])
server.addMiddleware(security_middleware);
server.returnJSON("/test", "{\"name\": \"john\", \"surname\": \"doe\"}");
server.returnHTML("/example", "<html><h1>Example</h1></html>");
server.runServer();
server.run();
return 0;
}
2 changes: 1 addition & 1 deletion src/teapot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ Teapot::Teapot(std::string ip_address, unsigned int port, unsigned int max_conne
#endif
}

void Teapot::runServer()
void Teapot::run()
{
socket.bindSocket();

Expand Down

0 comments on commit 4b5cf97

Please sign in to comment.