From 9b58f57b0cd9893a44c9d4381de4c82626242e94 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 3 May 2015 13:46:02 +0200 Subject: added handling for 404 cases (catch all) --- src/master.cpp | 14 ++++++++++++++ src/master.hpp | 2 ++ src/master_content.hpp | 1 + src/strusCms.cpp | 8 ++++++-- src/strusCms.hpp | 3 ++- 5 files changed, 25 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/master.cpp b/src/master.cpp index 0699051..086ebe3 100644 --- a/src/master.cpp +++ b/src/master.cpp @@ -2,6 +2,7 @@ #include "strusCms.hpp" #include +#include namespace apps { @@ -25,4 +26,17 @@ void master::ini( content::master &c ) c._root = cms.root( ); } +void master::register_common_pages( ) +{ + cms.dispatcher( ).assign( ".*", &master::not_found_404, this ); +} + +void master::not_found_404( ) +{ + content::master c; + ini( c ); + c.url = cms.request( ).script_name( ) + "/" + cms.request( ).path_info( ); + render( "not_found_404", c ); +} + } diff --git a/src/master.hpp b/src/master.hpp index 90bd985..520f258 100644 --- a/src/master.hpp +++ b/src/master.hpp @@ -16,6 +16,8 @@ class master : public cppcms::application { public: master( strusCms &cms ); void ini( content::master &c ); + void register_common_pages( ); + void not_found_404( ); }; } diff --git a/src/master_content.hpp b/src/master_content.hpp index 451ee7d..11eabd5 100644 --- a/src/master_content.hpp +++ b/src/master_content.hpp @@ -21,6 +21,7 @@ struct master : public cppcms::base_content { std::string register_link; std::string username; std::string _root; + std::string url; public: master( ) : cppcms::base_content( ) diff --git a/src/strusCms.cpp b/src/strusCms.cpp index 3858b32..b5e6b7b 100644 --- a/src/strusCms.cpp +++ b/src/strusCms.cpp @@ -22,8 +22,9 @@ namespace apps { strusCms::strusCms( cppcms::service &srv ) : cppcms::application( srv ), - intro( *this ), user( *this ), + intro( *this ), + master( *this ), conn( settings( ).get( "strusCms.db_connection" ) ), mail( settings( ).get( "strusCms.mail.server" ), settings( ).get( "strusCms.mail.port" ), @@ -38,8 +39,11 @@ strusCms::strusCms( cppcms::service &srv ) cppdb::session sql( conn ); sql.once( setup_dbconnection ); - add( intro ); add( user ); + add( intro ); + add( master ); + + master.register_common_pages( ); mapper( ).root( root( ) ); } diff --git a/src/strusCms.hpp b/src/strusCms.hpp index 579b2d7..9f2bba4 100644 --- a/src/strusCms.hpp +++ b/src/strusCms.hpp @@ -15,8 +15,9 @@ class strusCms : public cppcms::application { std::string root( std::string locale_name = "" ); public: - apps::intro intro; apps::user user; + apps::intro intro; + apps::master master; std::string conn; mailer mail; -- cgit v1.2.3-54-g00ecf