diff --git a/stuff/server.pl b/stuff/server.pl index e55e26a0..fe54a6ec 100644 --- a/stuff/server.pl +++ b/stuff/server.pl @@ -1,22 +1,60 @@ #!/bin/env perl +# Copyright (C) 2015 Alex Schroeder + +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see . + +my $wiki = $ARGV[0]||'wiki.pl'; +my $port = $ARGV[1]||8080; +my $dir = $ARGV[2]; +$ENV{WikiDataDir} = $dir if $dir; + { package Oddmuse::Server; use HTTP::Server::Simple::CGI; use base qw(HTTP::Server::Simple::CGI); - my $wiki = $ARGV[0]; - my $port = $ARGV[1]||'8080'; - my $dir = $ARGV[2]; + $OddMuse::RunCGI = 0; + do $wiki; # load just once + + sub handle_request { + my $self = shift; - die <<'EOT' unless $wiki; -Usage: perl server.pl WIKI [PORT [DIR]] + package OddMuse; + $q = shift; + + # NPH, or "no-parsed-header", scripts bypass the server completely by + # sending the complete HTTP header directly to the browser. + $q->nph(1); + + DoWikiRequest(); + } +} + +die <<'EOT' unless -f $wiki; +Usage: perl server.pl [WIKI [PORT [DIR]]] Example: perl server.pl wiki.pl 8080 ~/src/oddmuse/test-data -You need to provide the Oddmuse wiki script on the command line. If you provide -a data directory on the command line, this will override the WikiDataDir -environment variable. If neither is set, /tmp will be used. +You may provide the Oddmuse wiki script on the command line. If you do not +provide it, WIKI will default to 'wiki.pl'. + +You may provide a port number on the command line. If you do not provide it, +PORT will default to 8080. + +You may provide a data directory on the command line. It will be used to set the +environment variable 'WikiDataDir'. If it is not not set, Oddmuse will default +to '/tmp/oddmuse'. A simple test setup would be the following shell script: @@ -40,23 +78,7 @@ and when you're done, it'll kill the server for you. EOT - $ENV{WikiDataDir} = $dir if $dir; +my $server = Oddmuse::Server->new($port); - $OddMuse::RunCGI = 0; - do $wiki; - - sub handle_request { - my $self = shift; - my $cgi = shift; - wiki($cgi); - } - - sub wiki { - package OddMuse; - $q = shift; - DoWikiRequest(); - } -} - -# start the server -my $pid = Oddmuse::Server->new($port)->run(); +# $server->background(); +$server->run();