mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-14 04:57:21 +01:00
Cleaned up WebRoot.
This commit is contained in:
parent
15b9bb17e5
commit
dff3156138
@ -12,12 +12,13 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void WebRoot::load_settings() {
|
||||
void WebRoot::setup() {
|
||||
setup_error_handlers();
|
||||
setup_middleware();
|
||||
}
|
||||
|
||||
void WebRoot::setup_routes() {
|
||||
void WebRoot::setup_error_handlers() {
|
||||
default_error_handler_func = WebRoot::default_fallback_error_handler;
|
||||
|
||||
error_handler_map[404] = WebRoot::default_404_error_handler;
|
||||
}
|
||||
|
||||
@ -90,19 +91,12 @@ bool WebRoot::try_send_wwwroot_file(Request *request) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void WebRoot::send_error(int error_code, Request *request) {
|
||||
|
||||
}
|
||||
|
||||
void WebRoot::send_file(const std::string &path, Request *request) {
|
||||
std::string fp = FileCache::get_singleton()->wwwroot + path;
|
||||
|
||||
request->send_file(fp);
|
||||
}
|
||||
|
||||
void WebRoot::migrate() {
|
||||
}
|
||||
|
||||
void WebRoot::register_request_update(Request *request) {
|
||||
std::lock_guard<std::mutex> lock(_update_registered_requests_mutex);
|
||||
|
||||
@ -135,12 +129,13 @@ void WebRoot::update() {
|
||||
|
||||
WebRoot::WebRoot() :
|
||||
WebRouterNode() {
|
||||
|
||||
setup();
|
||||
}
|
||||
|
||||
WebRoot::~WebRoot() {
|
||||
main_route_map.clear();
|
||||
error_handler_map.clear();
|
||||
middlewares.clear();
|
||||
_middlewares.clear();
|
||||
}
|
||||
|
||||
std::string WebRoot::default_error_404_body = "<html><body>404 :(</body></html>";
|
||||
|
@ -17,13 +17,10 @@ class Request;
|
||||
|
||||
// FileCache -> set up, for this webroot, don't use singleton
|
||||
|
||||
// clean up unused things here
|
||||
// remove handler instances!
|
||||
|
||||
// Update the rest of the modules to the new systems
|
||||
|
||||
// remove middleware stack from request
|
||||
|
||||
class WebRoot : public WebRouterNode {
|
||||
RCPP_OBJECT(WebRoot, WebRouterNode);
|
||||
|
||||
@ -35,20 +32,17 @@ public:
|
||||
void handle_error_send_request(Request *request, const int error_code);
|
||||
|
||||
bool try_send_wwwroot_file(Request *request);
|
||||
void send_error(int error_code, Request *request);
|
||||
void send_file(const std::string &path, Request *request);
|
||||
|
||||
static void default_fallback_error_handler(Request *request, int error_code);
|
||||
static void default_404_error_handler(Request *request, int error_code);
|
||||
|
||||
virtual void load_settings();
|
||||
virtual void setup_routes();
|
||||
virtual void setup();
|
||||
virtual void setup_error_handlers();
|
||||
virtual void setup_middleware();
|
||||
|
||||
void default_routing_middleware(Object *instance, Request *request);
|
||||
|
||||
virtual void migrate();
|
||||
|
||||
void register_request_update(Request *request);
|
||||
void unregister_request_update(Request *request);
|
||||
void update();
|
||||
@ -57,10 +51,6 @@ public:
|
||||
virtual ~WebRoot();
|
||||
|
||||
public:
|
||||
HandlerInstance index_func;
|
||||
std::map<std::string, HandlerInstance> main_route_map;
|
||||
std::vector<HandlerInstance> middlewares;
|
||||
|
||||
Vector<Ref<Middleware> > _middlewares;
|
||||
|
||||
std::map<int, std::function<void(Request *, int)> > error_handler_map;
|
||||
|
Loading…
Reference in New Issue
Block a user