summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2015-07-31 13:43:19 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2015-07-31 13:43:19 +0200
commit54a304276fb361f95332c5c1f8c6f67026b1d96c (patch)
tree99ecbf787f2cff1593a77890b690a1f632e79733
parenta07e48f45e3b922a63aaae58b5bd816b8e324ee1 (diff)
downloadaCms-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
-rw-r--r--config.js1
-rw-r--r--src/master.cpp30
-rw-r--r--src/master.hpp2
-rw-r--r--src/strusCms.cpp10
-rw-r--r--src/strusCms.hpp2
5 files changed, 44 insertions, 1 deletions
diff --git a/config.js b/config.js
index b161536..df53d7c 100644
--- a/config.js
+++ b/config.js
@@ -14,6 +14,7 @@
"service" : {
"api" : "http",
+ "ip" : "0.0.0.0",
"port" : 8080
},
"http" : {
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 );
}
diff --git a/src/master.hpp b/src/master.hpp
index 520f258..d195601 100644
--- a/src/master.hpp
+++ b/src/master.hpp
@@ -17,6 +17,8 @@ class master : public cppcms::application {
master( strusCms &cms );
void ini( content::master &c );
void register_common_pages( );
+ void serve_file( std::string file_name );
+ void redirect_to_master( );
void not_found_404( );
};
diff --git a/src/strusCms.cpp b/src/strusCms.cpp
index 3a108f5..9d7945b 100644
--- a/src/strusCms.cpp
+++ b/src/strusCms.cpp
@@ -36,6 +36,7 @@ strusCms::strusCms( cppcms::service &srv )
{
locale_name = "en";
script = settings( ).get<std::string>( "strusCms.script" );
+ media = settings( ).get<std::string>( "strusCms.media" );
cppdb::session sql( conn );
sql.once( setup_dbconnection );
@@ -58,4 +59,13 @@ std::string strusCms::root( std::string l )
//~ return script + "/" + l;
}
+std::string strusCms::media_root( std::string l )
+{
+ return media;
+ // TODO: localization later
+ //~ if( l.empty( ) ) l = locale_name;
+ //~ return script + "/" + l;
+}
+
+
}
diff --git a/src/strusCms.hpp b/src/strusCms.hpp
index 285f026..83d4c8c 100644
--- a/src/strusCms.hpp
+++ b/src/strusCms.hpp
@@ -14,6 +14,7 @@ class strusCms : public cppcms::application {
public:
strusCms( cppcms::service &srv );
std::string root( std::string locale_name = "" );
+ std::string media_root( std::string locale_name = "" );
public:
apps::master master;
@@ -25,6 +26,7 @@ class strusCms : public cppcms::application {
private:
std::string script;
+ std::string media;
std::string locale_name;
};