lib/nitcorn/examples: customize server listening port
authorAlexis Laferrière <alexis.laf@xymus.net>
Fri, 18 Sep 2015 20:57:14 +0000 (16:57 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Sat, 7 Nov 2015 15:40:32 +0000 (10:40 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/nitcorn/examples/src/simple_file_server.nit
tests/sav/simple_file_server.res

index 69c177e..6613349 100644 (file)
@@ -14,7 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Basic file server on port 80, usually requires `root` to execute
+# Basic file server on port 80 by default, may require `root` to execute
 #
 # To be safe, it is recommended to run this program with its own username:
 # `sudo file_server -u nitcorn:www`
@@ -26,10 +26,10 @@ import privileges
 # Prepare options
 var opts = new OptionContext
 var opt_drop = new OptionUserAndGroup.for_dropping_privileges
-opt_drop.mandatory = true
+var opt_port = new OptionInt("Server port", 80, "--port", "-p")
 var opt_help = new OptionBool("Print this message", "--help", "-h")
-opts.add_option(opt_drop, opt_help)
-opts.parse(args)
+opts.add_option(opt_drop, opt_port, opt_help)
+opts.parse args
 
 # Check options errors and help
 if not opts.errors.is_empty or opt_help.value then
@@ -40,7 +40,7 @@ if not opts.errors.is_empty or opt_help.value then
 end
 
 # Serve everything with a standard FilesHandler
-var vh = new VirtualHost("localhost:80")
+var vh = new VirtualHost("localhost:{opt_port.value}")
 vh.routes.add new Route(null, new FileServer("www/hello_world/"))
 var factory = new HttpFactory.and_libevent
 factory.config.virtual_hosts.add vh
index 1d69303..12d09fe 100644 (file)
@@ -1,4 +1 @@
-Mandatory option -u, --usergroup not found.
-Usage: file_server [Options]
-  -u, --usergroup   Drop privileges to user:group or simply user
-  --help, -h        Print this message
+libevent warning: Opening localhost:80 failed