From 54a304276fb361f95332c5c1f8c6f67026b1d96c Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Fri, 31 Jul 2015 13:43:19 +0200 Subject: made it possible to run standalone without proxying webserver: - deliver static pages - some default redirects pointing to the main landing page --- src/master.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/master.cpp') 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 #include +#include + 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 ); } -- cgit v1.2.3-54-g00ecf