summaryrefslogtreecommitdiff
path: root/src/master.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/master.cpp')
-rw-r--r--src/master.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/master.cpp b/src/master.cpp
index 086ebe3..bd3e5df 100644
--- a/src/master.cpp
+++ b/src/master.cpp
@@ -4,6 +4,8 @@
#include <cppcms/service.h>
#include <cppcms/url_dispatcher.h>
+#include <fstream>
+
namespace apps {
master::master( strusCms &cms )
@@ -28,14 +30,40 @@ void master::ini( content::master &c )
void master::register_common_pages( )
{
+ // only deliver static content here matching the static files only!
+ cms.dispatcher( ).assign( "(" + cms.media_root( ) + "/basic-profile.css)", &master::serve_file, this, 1 );
+ cms.dispatcher( ).assign( "(" + cms.media_root( ) + "/images/strus_big.jpg)", &master::serve_file, this, 1 );
+
+ // some catch all redirects pointing to the main page
+ cms.dispatcher( ).assign( "/", &master::redirect_to_master, this );
+ cms.dispatcher( ).assign( "", &master::redirect_to_master, this );
+
+ // everything else in an error
cms.dispatcher( ).assign( ".*", &master::not_found_404, this );
}
+void master::serve_file( std::string file_name )
+{
+ std::ifstream f( ( "./" + file_name ).c_str( ) );
+ if( !f ) {
+ not_found_404( );
+ return;
+ }
+
+ response( ).content_type( "application/octet-stream" );
+ response( ).out( ) << f.rdbuf( );
+}
+
+void master::redirect_to_master( )
+{
+ response( ).set_redirect_header( cms.root( ) );
+}
+
void master::not_found_404( )
{
content::master c;
ini( c );
- c.url = cms.request( ).script_name( ) + "/" + cms.request( ).path_info( );
+ c.url = cms.request( ).script_name( ) + cms.request( ).path_info( );
render( "not_found_404", c );
}