diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2015-07-31 13:43:19 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2015-07-31 13:43:19 +0200 |
commit | 54a304276fb361f95332c5c1f8c6f67026b1d96c (patch) | |
tree | 99ecbf787f2cff1593a77890b690a1f632e79733 /src/master.cpp | |
parent | a07e48f45e3b922a63aaae58b5bd816b8e324ee1 (diff) | |
download | aCms-54a304276fb361f95332c5c1f8c6f67026b1d96c.tar.gz aCms-54a304276fb361f95332c5c1f8c6f67026b1d96c.tar.bz2 |
made it possible to run standalone without proxying webserver:
- deliver static pages
- some default redirects pointing to the main landing page
Diffstat (limited to 'src/master.cpp')
-rw-r--r-- | src/master.cpp | 30 |
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 ); } |