Skip to content

Commit 2bac6ba

Browse files
author
DelphiDabbler
committed
Changed how test web server is specified.
Formerly the -localhost command line option made CodeSnip use hard wired 'localhost:8080' as the test server. Now the -localhost switch has been replaced by the --test-server command line option which is used to name the test server. This means that any future changes to the test server or its port number will not require a new version of CodeSnip.
1 parent 909a03a commit 2bac6ba

File tree

1 file changed

+71
-25
lines changed

1 file changed

+71
-25
lines changed

Src/Web.UInfo.pas

Lines changed: 71 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
44
* obtain one at http://mozilla.org/MPL/2.0/
55
*
6-
* Copyright (C) 2009-2014, Peter Johnson (www.delphidabbler.com).
6+
* Copyright (C) 2009-2016, Peter Johnson (www.delphidabbler.com).
77
*
88
* $Rev$
99
* $Date$
@@ -67,25 +67,29 @@ TWebProxyInfo = record
6767
TWebInfo = class(TNoConstructObject)
6868
strict private
6969
const
70-
/// <summary>Remote DelphiDabbler web server.</summary>
71-
RemoteHost = 'delphidabbler.com';
70+
/// <summary>Name of server that hosts tested and released web services
71+
/// that are used by CodeSnip.</summary>
72+
/// <remarks>There is also a test server that can be used by CodeSnip
73+
/// where new and updated web services are tested - see
74+
/// <c>TestServerHost</c> below.</remarks>
75+
ProductionServerHost = 'delphidabbler.com';
7276
/// <summary>URL of DelphiDabbler website.</summary>
73-
WebsiteURL = 'http://' + RemoteHost;
77+
WebsiteURL = 'http://' + ProductionServerHost;
7478
/// <summary>Template for URL of Code Snippets news feed.</summary>
7579
/// <remarks>'%d' placeholder must be replaced by the required number of
7680
/// days into the past the news feed should cover.</remarks>
7781
NewsFeedTplt = WebSiteURL + '/feeds/site-news-feed?id=codesnip&days=%d';
7882
strict private
79-
/// <summary>Returns the name of the host server to be used.</summary>
80-
/// <remarks>This is the remote web server unless the '-localhost# switch
81-
/// was passed on the command line when localhost server is returned.
82-
/// </remarks>
83+
/// <summary>Returns the name of the server that hosts web services that
84+
/// are used by CodeSnip.</summary>
85+
/// <remarks>By default is the production server (as specified by the
86+
/// <c>ProductionServerHost</c> constant. CodeSnip will instead use a
87+
/// test server (as returned by the <c>TestServerHost</c> method) if the
88+
/// name and port of the test server is passed on the command line via the
89+
/// <c>--test-server</c> command line option.</remarks>
8390
class function Host: string;
8491
public
8592
const
86-
/// <summary>Local web server.</summary>
87-
/// <remarks>Used for test purposes.</remarks>
88-
LocalHost = 'localhost:8080';
8993
/// <summary>URL of home page on DelphiDabbler website.</summary>
9094
DelphiDabblerHomeURL = WebsiteURL + '/';
9195
/// <summary>URL of home page of the CodeSnip project.</summary>
@@ -101,6 +105,24 @@ TWebInfo = class(TNoConstructObject)
101105
/// <summary>URL of CodeSnip's FAQ web page.</summary>
102106
FAQsURL = WebsiteURL + '/url/codesnip-faq';
103107
public
108+
/// <summary>Returns the name of the server that hosts web services used by
109+
/// CodeSnip when under testing. This server receives updated web services
110+
/// before they are released to the production server.</summary>
111+
/// <remarks>
112+
/// <para>The name of this server must be passed on the command line via
113+
/// the <c>--test-server</c> option. If this option is not specified then
114+
/// <c>TestServerHost</c> returns the empty string.</para>
115+
/// <para>The format of the command line switch is
116+
/// <c>--test-server=server-name</c> or
117+
/// <c>--test-server=server-name:port</c> where <c>server-name</c> is the
118+
/// name of the test server and <c>port</c> is the port number it is
119+
/// operating on, for example <c>--test-server=localhost:8080</c> or
120+
/// <c>--test-server=test.delphidabbler.com</c>. The
121+
/// port number and its preceding ':' character can be omitted if the
122+
/// server is on port 80.</para>
123+
/// <para>The server must be using the <c>http://</c> protocol.</para>
124+
/// </remarks>
125+
class function TestServerHost: string;
104126
/// <summary>Builds the URL of the CodeSnip news feed.</summary>
105127
/// <param name="Age">Word [in] Maximum age, in days, of news items to be
106128
/// included in the feed.</param>
@@ -114,17 +136,18 @@ TWebInfo = class(TNoConstructObject)
114136
/// <summary>Gets information about any required web proxy.</summary>
115137
/// <remarks>The web proxy information is read from settings.</remarks>
116138
class function WebProxyInfo: TWebProxyInfo;
117-
/// <summary>Checks if the program is using the web server on localhost.
118-
/// </summary>
119-
/// <returns>Boolean. True if localhost is being used, False if the remote,
120-
/// production, server is being used.</returns>
139+
/// <summary>Checks if the program is using a test web server.</summary>
140+
/// <returns><c>Boolean</c>. <c>True</c> if a test web server is being
141+
/// used, <c>False</c> if the production web server is being used.
142+
/// </returns>
121143
/// <remarks>
122-
/// <para>True is returned iff the '-localhost' switch was passed on the
123-
/// command line.</para>
124-
/// <para>Localhost should only be used by developers with access to a
125-
/// suitable test server running as 'locahost'.</para>
144+
/// <para><c>True</c> is returned iff a valid <c>--test-server</c> command
145+
/// line option was supplied on the command line.</para>
146+
/// <para><c>--test-server</c> should only be specified by developers with
147+
/// access to a suitable test server.</para>
148+
126149
/// </remarks>
127-
class function UsingLocalHost: Boolean;
150+
class function UsingTestServer: Boolean;
128151
end;
129152

130153

@@ -142,20 +165,43 @@ implementation
142165

143166
class function TWebInfo.Host: string;
144167
begin
145-
if UsingLocalHost then
146-
Result := LocalHost
168+
if UsingTestServer then
169+
Result := TestServerHost
147170
else
148-
Result := RemoteHost;
171+
Result := ProductionServerHost;
149172
end;
150173

151174
class function TWebInfo.NewsFeedURL(const Age: Word): string;
152175
begin
153176
Result := Format(NewsFeedTplt, [Age]);
154177
end;
155178

156-
class function TWebInfo.UsingLocalHost: Boolean;
179+
class function TWebInfo.TestServerHost: string;
180+
const
181+
TestServerSwitch = '--test-server';
182+
Separator = '=';
183+
var
184+
Idx: Integer;
185+
ParamName: string;
186+
ParamValue: string;
187+
begin
188+
for Idx := 1 to ParamCount do
189+
begin
190+
if not StrContainsStr(Separator, ParamStr(Idx)) then
191+
Continue;
192+
StrSplit(ParamStr(Idx), Separator, ParamName, ParamValue);
193+
if not StrSameStr(TestServerSwitch, ParamName) then
194+
Continue;
195+
if ParamValue = EmptyStr then
196+
Continue;
197+
Exit(ParamValue);
198+
end;
199+
Result := EmptyStr;
200+
end;
201+
202+
class function TWebInfo.UsingTestServer: Boolean;
157203
begin
158-
Result := FindCmdLineSwitch('localhost', True);
204+
Result := TestServerHost <> EmptyStr;
159205
end;
160206

161207
class function TWebInfo.WebProxyInfo: TWebProxyInfo;

0 commit comments

Comments
 (0)