Browse Source

FileServer: commandline option for setting listening host (default: 127.0.0.1)

Manfred Kroehnert 12 years ago
parent
commit
82eda147d3
2 changed files with 74 additions and 10 deletions
  1. 16 3
      server/FileServer.st
  2. 58 7
      server/server.js

+ 16 - 3
server/FileServer.st

@@ -1,6 +1,6 @@
 Smalltalk current createPackage: 'FileServer'!
 Object subclass: #FileServer
-	instanceVariableNames: 'path http fs url port basePath util username password fallbackPage'
+	instanceVariableNames: 'path http fs url host port basePath util username password fallbackPage'
 	package: 'FileServer'!
 
 !FileServer methodsFor: 'accessing'!
@@ -21,6 +21,14 @@ fallbackPage: aString
 	fallbackPage := aString
 !
 
+host
+	^host
+!
+
+host: hostname
+	host := hostname
+!
+
 password: aPassword
 	password := aPassword.
 !
@@ -60,6 +68,7 @@ initialize
 	fs := self require: 'fs'.
 	util := self require: 'util'.
 	url := self require: 'url'.
+	host := self class defaultHost.
 	port := self class defaultPort.
 	username := nil.
 	password := nil.
@@ -233,8 +242,8 @@ start
 	(http createServer: [:request :response |
 	      self handleRequest: request respondTo: response])
 	      on: 'error' do: [:error | console log: 'Error starting server: ', error];
-	      on: 'listening' do: [console log: 'Starting file server on port ', self port asString];
-	      listen: self port.
+	      on: 'listening' do: [console log: 'Starting file server on ', self host, ':', self port asString];
+	      listen: self port host: self host.
 !
 
 startOn: aPort
@@ -673,6 +682,10 @@ defaultMimeTypes
 	}
 !
 
+defaultHost
+	^'127.0.0.1'
+!
+
 defaultPort
 	^4000
 !

+ 58 - 7
server/server.js

@@ -16763,7 +16763,7 @@ smalltalk.addClass('ProtocolRemoved', smalltalk.ProtocolAnnouncement, [], 'Kerne
 
 
 smalltalk.addPackage('FileServer');
-smalltalk.addClass('FileServer', smalltalk.Object, ['path', 'http', 'fs', 'url', 'port', 'basePath', 'util', 'username', 'password', 'fallbackPage'], 'FileServer');
+smalltalk.addClass('FileServer', smalltalk.Object, ['path', 'http', 'fs', 'url', 'host', 'port', 'basePath', 'util', 'username', 'password', 'fallbackPage'], 'FileServer');
 smalltalk.addMethod(
 smalltalk.method({
 selector: "base64Decode:",
@@ -17001,6 +17001,40 @@ referencedClasses: []
 }),
 smalltalk.FileServer);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "host",
+category: 'accessing',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+$1=self["@host"];
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"host",{},smalltalk.FileServer)})},
+args: [],
+source: "host\x0a\x09^host",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.FileServer);
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "host:",
+category: 'accessing',
+fn: function (hostname){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+self["@host"]=hostname;
+return self}, function($ctx1) {$ctx1.fill(self,"host:",{hostname:hostname},smalltalk.FileServer)})},
+args: ["hostname"],
+source: "host: hostname\x0a\x09host := hostname",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.FileServer);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "initialize",
@@ -17014,14 +17048,15 @@ self["@http"]=_st(self)._require_("http");
 self["@fs"]=_st(self)._require_("fs");
 self["@util"]=_st(self)._require_("util");
 self["@url"]=_st(self)._require_("url");
+self["@host"]=_st(_st(self)._class())._defaultHost();
 self["@port"]=_st(_st(self)._class())._defaultPort();
 self["@username"]=nil;
 self["@password"]=nil;
 self["@fallbackPage"]=nil;
 return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.FileServer)})},
 args: [],
-source: "initialize\x0a\x09super initialize.\x0a\x09path := self require: 'path'.\x0a\x09http := self require: 'http'.\x0a\x09fs := self require: 'fs'.\x0a\x09util := self require: 'util'.\x0a\x09url := self require: 'url'.\x0a\x09port := self class defaultPort.\x0a\x09username := nil.\x0a\x09password := nil.\x0a\x09fallbackPage := nil.",
-messageSends: ["initialize", "require:", "defaultPort", "class"],
+source: "initialize\x0a\x09super initialize.\x0a\x09path := self require: 'path'.\x0a\x09http := self require: 'http'.\x0a\x09fs := self require: 'fs'.\x0a\x09util := self require: 'util'.\x0a\x09url := self require: 'url'.\x0a\x09host := self class defaultHost.\x0a\x09port := self class defaultPort.\x0a\x09username := nil.\x0a\x09password := nil.\x0a\x09fallbackPage := nil.",
+messageSends: ["initialize", "require:", "defaultHost", "class", "defaultPort"],
 referencedClasses: []
 }),
 smalltalk.FileServer);
@@ -17335,13 +17370,13 @@ return _st(console)._log_(_st("Error starting server: ").__comma(error));
 }, function($ctx2) {$ctx2.fillBlock({error:error},$ctx1)})}));
 _st($1)._on_do_("listening",(function(){
 return smalltalk.withContext(function($ctx2) {
-return _st(console)._log_(_st("Starting file server on port ").__comma(_st(_st(self)._port())._asString()));
+return _st(console)._log_(_st(_st(_st("Starting file server on ").__comma(_st(self)._host())).__comma(":")).__comma(_st(_st(self)._port())._asString()));
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
-$2=_st($1)._listen_(_st(self)._port());
+$2=_st($1)._listen_host_(_st(self)._port(),_st(self)._host());
 return self}, function($ctx1) {$ctx1.fill(self,"start",{},smalltalk.FileServer)})},
 args: [],
-source: "start\x0a\x09\x22Checks if required directory layout is present (issue warning if not).\x0a\x09 Afterwards start the server.\x22\x0a\x09self checkDirectoryLayout.\x0a\x09(http createServer: [:request :response |\x0a\x09      self handleRequest: request respondTo: response])\x0a\x09      on: 'error' do: [:error | console log: 'Error starting server: ', error];\x0a\x09      on: 'listening' do: [console log: 'Starting file server on port ', self port asString];\x0a\x09      listen: self port.",
-messageSends: ["checkDirectoryLayout", "on:do:", "log:", ",", "createServer:", "handleRequest:respondTo:", "asString", "port", "listen:"],
+source: "start\x0a\x09\x22Checks if required directory layout is present (issue warning if not).\x0a\x09 Afterwards start the server.\x22\x0a\x09self checkDirectoryLayout.\x0a\x09(http createServer: [:request :response |\x0a\x09      self handleRequest: request respondTo: response])\x0a\x09      on: 'error' do: [:error | console log: 'Error starting server: ', error];\x0a\x09      on: 'listening' do: [console log: 'Starting file server on ', self host, ':', self port asString];\x0a\x09      listen: self port host: self host.",
+messageSends: ["checkDirectoryLayout", "on:do:", "log:", ",", "createServer:", "handleRequest:respondTo:", "asString", "port", "host", "listen:host:"],
 referencedClasses: []
 }),
 smalltalk.FileServer);
@@ -17510,6 +17545,22 @@ referencedClasses: ["Array"]
 }),
 smalltalk.FileServer.klass);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "defaultHost",
+category: 'accessing',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+return "127.0.0.1";
+}, function($ctx1) {$ctx1.fill(self,"defaultHost",{},smalltalk.FileServer.klass)})},
+args: [],
+source: "defaultHost\x0a\x09^'127.0.0.1'",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.FileServer.klass);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "defaultMimeTypes",