From: Alexis Laferrière Date: Tue, 10 Nov 2015 17:37:44 +0000 (-0500) Subject: contrib/tnitter: refactor to set the server interface at compilation X-Git-Tag: v0.8~88^2~5 X-Git-Url: http://nitlanguage.org contrib/tnitter: refactor to set the server interface at compilation Signed-off-by: Alexis Laferrière --- diff --git a/contrib/tnitter/Makefile b/contrib/tnitter/Makefile index 9ac2dc9..2f6efba 100644 --- a/contrib/tnitter/Makefile +++ b/contrib/tnitter/Makefile @@ -1,8 +1,10 @@ +SERVER ?= localhost:8080 + all: bin/tnitter_server bin/tnitter bin/tnitter_server: $(shell ../../bin/nitls -M src/tnitter.nit) mkdir -p bin/ - ../../bin/nitc -o bin/tnitter_server src/tnitter.nit + ../../bin/nitc -o bin/tnitter_server src/tnitter.nit -D tnitter_interface=$(SERVER) bin/tnitter: $(shell ../../bin/nitls -M src/tnitter_app.nit) mkdir -p bin/ diff --git a/contrib/tnitter/src/tnitter.nit b/contrib/tnitter/src/tnitter.nit index e0311a3..4b175c2 100644 --- a/contrib/tnitter/src/tnitter.nit +++ b/contrib/tnitter/src/tnitter.nit @@ -30,6 +30,9 @@ redef class OptionContext init do add_option(drop, help) end +# Address and port of the listening socket +fun tnitter_interface: String do return "localhost:8080" + # Avoid executing when running tests if "NIT_TESTING".environ == "true" then exit 0 @@ -43,14 +46,8 @@ if not opts.errors.is_empty or opts.help.value then exit 1 end -# If we can, we use port 80 -var interfac -if sys.uid == 0 then # Are we root? - interfac = "localhost:80" -else interfac = "localhost:8080" - # Setup server -var vh = new VirtualHost(interfac) +var vh = new VirtualHost(tnitter_interface) var factory = new HttpFactory.and_libevent factory.config.virtual_hosts.add vh @@ -64,5 +61,5 @@ vh.routes.add new Route("/push/", new TnitterPush) vh.routes.add new Route(null, new TnitterWeb) # Run -print "Launching server on http://{interfac} ..." +print "Launching server on http://{tnitter_interface} ..." factory.run