Web framework C++  2.0.0
Simple web framework on c++ designed to easily create web pages, etc
app.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <list>
4 #include <unordered_map>
5 #include "handler.h"
6 #include "network.h"
7 #include "redirect_response.h"
8 #include "log_manager.h"
9 
20 class App {
21  Network network;
22  std::unordered_map<std::string, Handler *> handlersRoutes;
23  Handler * handler;
24  std::list<RedirectResponse> redirects;
25  std::vector<Middleware *> middlewareList;
26  Context context;
27  LogManager log;
28 public:
42  explicit App(
43  const char * ip = "127.0.0.1",
44  int port = 80,
45  bool isIPv6 = false,
46  const char * logFilePath = nullptr
47  );
48 
55  explicit App(InitParams & params);
56 
60  ~App();
61 
70  bool init();
71 
79  void addHandler(Handler * handler);
80 
91  void addPermanentlyRedirect(const char * uri, const char * target);
92 
104  void addTemporaryRedirect(const char * uri, const char * target);
105 
119  void addRedirect(const char * uri, const char * target, int code);
120 
129  void addMiddleware(Middleware * middleware);
130 
136  bool run();
137 };
This class is wrapper for important data (like Response, DB, Middleware etc.), which is needed to han...
Definition: context.h:17
bool init()
~App()
App(const char *ip="127.0.0.1", int port=80, bool isIPv6=false, const char *logFilePath=nullptr)
InitParams is intended to get web-server configs from command line arguments.
Definition: init_params.h:10
Network bridge pattern.
Definition: network.h:9
void addMiddleware(Middleware *middleware)
object of this class executes every time on new request, this object (and others) construct response ...
Definition: handler.h:13
class wrapper for middleware
Definition: middleware.h:14
void addPermanentlyRedirect(const char *uri, const char *target)
void addHandler(Handler *handler)
void addRedirect(const char *uri, const char *target, int code)
void addTemporaryRedirect(const char *uri, const char *target)
The main class of the framework. Each object of this class is an independent web-application, which could be configured by handlers, middleware etc.
Definition: app.h:20
bool run()
logging info into file
Definition: log_manager.h:11