magpie
Loading...
Searching...
No Matches
AppDecl.hpp
1#pragma once
2
3#include "magpie/config/AppConfig.hpp"
4#include "magpie/handlers/StatusHandlers.hpp"
5#include "magpie/middlewares/Middleware.hpp"
6#include "magpie/routing/BaseRouter.hpp"
7
8namespace magpie {
9
14class BaseApp {
15protected:
16 const AppConfig config;
17public:
18 BaseApp(AppConfig&& config) : config(std::move(config)) {}
19 virtual ~BaseApp() = default;
20
21 virtual const routing::BaseRouter& getRouter() = 0;
22
23 virtual void run() = 0;
24 virtual void shutdown() = 0;
25 virtual data::CommonData* getContext() const = 0;
26 const AppConfig& getConfig() { return config; }
27};
28
36template <data::IsCommonData ContextType = data::CommonData>
37class ContextApp : public BaseApp {
38public:
39 std::shared_ptr<StatusHandlerNotFound<ContextType>> notFoundErrorHandler
40 = std::make_shared<StatusHandlerNotFound<ContextType>>();
41 std::shared_ptr<StatusHandler500<ContextType>> errorHandler
42 = std::make_shared<StatusHandler500<ContextType>>();
43
44 ContextApp(AppConfig&& config) : BaseApp(std::move(config)) {}
45 virtual ~ContextApp() = default;
46
47 template <typename T>
48 void useNotFoundErrorHandler() {
49 notFoundErrorHandler = std::make_shared<T>();
50 }
51
52 template <typename T>
53 void use500ErrorHandler() {
54 errorHandler = std::make_shared<T>();
55 }
56
57 virtual Middlewares<ContextType>* getMiddlewaresAsPtr() = 0;
58};
59
60}
Definition BaseRouter.hpp:9
Definition AppConfig.hpp:11
Definition Middleware.hpp:145
Definition CommonData.hpp:8