~otheb/kb

4db1fe839491601333a63eb991c1f57db2c91b02 — Olie Ayre 2 months ago cfc6f06
Added "static-dir" option to WUI

This points to the directory containing the static content (CSS).
2 files changed, 13 insertions(+), 24 deletions(-)

M kb-web/main.d
D kb-web/static/err.html
M kb-web/main.d => kb-web/main.d +13 -13
@@ 23,6 23,7 @@ ushort PORT         = 80               ;
string FRIENDLYNAME = "KB Web UI"      ;
bool   LIGHTTHEME   = false            ;
string SERVER       = "localhost:8000" ;
string STATICDIR    = "./static"       ;

int main( string[] args ) {
	// read config


@@ 46,24 47,22 @@ int main( string[] args ) {
	if ( isFile( CONFFILE ) ) { readconf( CONFFILE.readText() ) ; }

	// display config options on startup
	writeln( "           Port : " , PORT ) ;
	writeln( "  Friendly name : " , FRIENDLYNAME ) ;
	writeln( "Use light theme : " , LIGHTTHEME ) ;
	writeln( "     API server : " , SERVER ) ;
	writeln( "              Port : " , PORT ) ;
	writeln( "     Friendly name : " , FRIENDLYNAME ) ;
	writeln( "   Use light theme : " , LIGHTTHEME ) ;
	writeln( "        API server : " , SERVER ) ;
	writeln( "Static content dir : " , STATICDIR ) ;

	Server server = new Server() ;
	server.host( "0.0.0.0" , PORT ) ;
	server.host( "::" , PORT ) ;
	server.router.add( new router() ) ;
	server.router.add( Get( "global.css" ) ,
	                   new Resource( "text/css" ,
	                                 readText( "static/global.css" ) ) ) ;
	server.router.add( Get( "light.css" ) ,
	                   new Resource( "text/css" ,
	                                 readText( "static/light.css" ) ) ) ;
	server.router.add( Get( "dark.css" ) ,
	                   new Resource( "text/css" ,
	                                 readText( "static/dark.css" ) ) ) ;
	server.router.add( Get( "global.css" ) , new Resource( "text/css" ,
	                   readText( buildPath( STATICDIR , "global.css" ) ) ) ) ;
	server.router.add( Get( "light.css" ) , new Resource( "text/css" ,
	                   readText( buildPath( STATICDIR , "light.css" ) ) ) ) ;
	server.router.add( Get( "dark.css" ) , new Resource( "text/css" ,
	                   readText( buildPath( STATICDIR , "dark.css" ) ) ) ) ;
	server.run() ;
	return 0 ;
}


@@ 78,6 77,7 @@ void readconf( string content ) {
		LIGHTTHEME = j["light-theme"].boolean ;
	}
	if ( ( "server" in j ) !is null ) { SERVER = j["server"].str ; }
	if ( ( "static-dir" in j ) !is null ) { STATICDIR = j["static-dir"].str ; }
}

string fmtdate( long ts ) {

D kb-web/static/err.html => kb-web/static/err.html +0 -11
@@ 1,11 0,0 @@
<!DOCTYPE html>
<head>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="/global.css">
	<title>Error</title>
</head>
<body>
	<h1>Oh no</h1>
	The API server didn't send back the right information. Check the API server
	is up and kb-web is pointing at it.
</body>