diff --git a/modules/web/SCsub b/modules/web/SCsub index a07b0f68f..faa46af36 100644 --- a/modules/web/SCsub +++ b/modules/web/SCsub @@ -61,6 +61,7 @@ sources = [ #"nodes/paged_article/paged_articles_md_index_web_page.cpp", "nodes/redirect/redirect_web_page.cpp", + "nodes/redirect/alias_web_page.cpp", ] if ARGUMENTS.get('custom_modules_shared', 'no') == 'yes': diff --git a/modules/web/config.py b/modules/web/config.py index cf376b393..cbd448707 100644 --- a/modules/web/config.py +++ b/modules/web/config.py @@ -76,6 +76,7 @@ def get_doc_classes(): "PagedArticlesWebPageMDIndex", "RedirectWebPage", + "AliasWebPage", ] diff --git a/modules/web/nodes/redirect/alias_web_page.cpp b/modules/web/nodes/redirect/alias_web_page.cpp new file mode 100644 index 000000000..4328133db --- /dev/null +++ b/modules/web/nodes/redirect/alias_web_page.cpp @@ -0,0 +1,40 @@ +#include "alias_web_page.h" + +#include "../../http/http_server_enums.h" +#include "../../http/web_server_request.h" +#include "core/os/file_access.h" + +NodePath AliasWebPage::get_alias_path() { + return _alias_path; +} +void AliasWebPage::set_alias_path(const NodePath &val) { + _alias_path = val; +} + +void AliasWebPage::_handle_request(Ref request) { + ERR_FAIL_COND(!_alias); + ERR_FAIL_COND(!ObjectDB::instance_validate(_alias)); + + _alias->handle_request(request); +} + +AliasWebPage::AliasWebPage() { + _alias = nullptr; +} + +AliasWebPage::~AliasWebPage() { +} + +void AliasWebPage::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE) { + _alias = Object::cast_to(get_node_or_null(_alias_path)); + } else if (p_what == NOTIFICATION_EXIT_TREE) { + _alias = nullptr; + } +} + +void AliasWebPage::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_alias_path"), &AliasWebPage::get_alias_path); + ClassDB::bind_method(D_METHOD("set_alias_path", "val"), &AliasWebPage::set_alias_path); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "alias_path"), "set_alias_path", "get_alias_path"); +} diff --git a/modules/web/nodes/redirect/alias_web_page.h b/modules/web/nodes/redirect/alias_web_page.h new file mode 100644 index 000000000..d68b1d2c1 --- /dev/null +++ b/modules/web/nodes/redirect/alias_web_page.h @@ -0,0 +1,34 @@ +#ifndef ALIAS_WEB_PAGE_H +#define ALIAS_WEB_PAGE_H + +#include "core/ustring.h" + +#include "../../http/web_node.h" + +class WebServerRequest; + +class AliasWebPage : public WebNode { + GDCLASS(AliasWebPage, WebNode); + +public: + NodePath get_alias_path(); + void set_alias_path(const NodePath &val); + + int get_code(); + void set_code(const int val); + + void _handle_request(Ref request); + + AliasWebPage(); + ~AliasWebPage(); + +protected: + void _notification(int p_what); + + static void _bind_methods(); + + NodePath _alias_path; + WebNode *_alias; +}; + +#endif diff --git a/modules/web/register_types.cpp b/modules/web/register_types.cpp index 8bb5ac44b..a03e27a40 100644 --- a/modules/web/register_types.cpp +++ b/modules/web/register_types.cpp @@ -60,6 +60,7 @@ SOFTWARE. #include "nodes/paged_article/paged_articles_web_page.h" //#include "nodes/paged_article/paged_articles_md_index.h" +#include "nodes/redirect/alias_web_page.h" #include "nodes/redirect/redirect_web_page.h" void register_web_types() { @@ -126,6 +127,7 @@ void register_web_types() { //ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_class(); } void unregister_web_types() {