<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title></title>
</head>
<body>
<br>
<br>
Avi Bryant wrote:<br>
<blockquote type="cite"
 cite="midPine.LNX.4.43L0.0308301107050.32194-100000@cable.beta4.com">
  <pre wrap="">On Sat, 30 Aug 2003, Giovanni Giorgi wrote:

  </pre>
  <blockquote type="cite">
    <pre wrap="">For example I'd like to serve static html documentation and so on.
I do not want to install another http server.
I have tryed the KomHttpServer-6.1 but i get some errors when I use it.
    </pre>
  </blockquote>
  <pre wrap=""><!---->
What are the problems you're having with Kom 6.1?
I've had success using Comanche 5 to serve static content alongside
Seaside.  You have to use the ChieftainModule to attach both a WAKom
module and a file serving module (forget the class name) to the same port
on different paths.
  </pre>
</blockquote>
<br>
I also serve static content along side Seaside, plus I allow virtual hosting
of many domains simultaneously. &nbsp;To do this, rather than using the ChieftainModule,
I created a subclass of WAKom, which I call ComancheInterface (for lack of
a better name). &nbsp;It has the following #process: method:<br>
<br>
process: aRequest <br>
&nbsp;&nbsp;&nbsp; "This is the required Comanche method that kicks everything off.&nbsp; <br>
&nbsp;&nbsp;&nbsp; Nothing else works until this method is properly run, and it will&nbsp; <br>
&nbsp;&nbsp;&nbsp; automatically be run by Comanche."<br>
&nbsp;&nbsp;&nbsp; | url |<br>
&nbsp;&nbsp;&nbsp; httpRequest _ aRequest.<br>
&nbsp;&nbsp;&nbsp; url _ httpRequest url.<br>
&nbsp;&nbsp;&nbsp; (url beginsWith: '/seaside/')<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ifTrue: [^super process: aRequest].<br>
&nbsp;&nbsp;&nbsp; WebHit logRequest: aRequest.<br>
&nbsp;&nbsp;&nbsp; ((url beginsWith: '/secure/')<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; and: [httpRequest ipString ~= '127.0.0.1'])<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ifTrue: [^ self redirectToSecurePort].<br>
&nbsp;&nbsp;&nbsp; (url endsWithAnyOf: MicrosoftRedirects)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ifTrue: [^ self redirectToMicrosoft].<br>
&nbsp;&nbsp;&nbsp; (url endsWithAnyOf: SenderRedirects)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ifTrue: [^ self redirectToSender].<br>
&nbsp;&nbsp;&nbsp; self processMultipartFields: aRequest.<br>
&nbsp;&nbsp;&nbsp; ^ self siteManager process: httpRequest<br>
<br>
My three 'redirect' methods are implemented thus:<br>
<br>
redirectToMicrosoft<br>
&nbsp;&nbsp;&nbsp; "So that I can redirect all the NT/XP/2K virii to the originator of the
<br>
&nbsp;&nbsp;&nbsp; problem "<br>
&nbsp;&nbsp;&nbsp; ^ httpRequest redirectTo: '<a class="moz-txt-link-freetext" href="http://www.microsoft.com">http://www.microsoft.com</a>'<br>
<br>
<br>
redirectToSecurePort<br>
&nbsp;&nbsp;&nbsp; "In case they hit my secure pages via port 80 instead of port 443"<br>
&nbsp;&nbsp;&nbsp; ^ httpRequest redirectTo: '<a class="moz-txt-link-freetext" href="https://">https://</a>' , httpRequest host , '/' , httpRequest
url<br>
<br>
<br>
redirectToSender<br>
&nbsp;&nbsp;&nbsp; "Primarily so that requests from kiddie scripts that are probing the
<br>
&nbsp;&nbsp;&nbsp; system can just get routed back to the originator."<br>
&nbsp;&nbsp;&nbsp; ^ httpRequest redirectTo: '<a class="moz-txt-link-freetext" href="http://">http://</a>' , httpRequest ipString , httpRequest
url<br>
<br>
<br>
The #siteManager method is implemented thus:<br>
<br>
siteManager<br>
&nbsp;&nbsp;&nbsp; | tok site host |<br>
&nbsp;&nbsp;&nbsp; site _ 'default'.<br>
&nbsp;&nbsp;&nbsp; host _ httpRequest host.<br>
&nbsp;&nbsp;&nbsp; host notNil<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ifTrue: [tok _ host findTokens: '.'.<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tok size &gt; 1<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ifTrue: [site _ tok at: tok size - 1].<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tok size = 1<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ifTrue: [site _ tok last].<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (SiteMap includesKey: site)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ifFalse: [site _ 'default']].<br>
&nbsp;&nbsp;&nbsp; ^ (SiteMap at: site) default<br>
<br>
The SiteMap is a class var containing a dictionary. &nbsp;The keys of the dictionary
contain the domain names that I host, and the values are the individual classes
that handle serving content for each particular domain. &nbsp;Thus, I can have
a customized handler for each domain that I host (it also will automatically
use a default handler class if some other isn't explicitly specified in the
SiteMap). &nbsp;The only mandatory instance method those handler classes must
implement is #process:<br>
<br>
The default site handler class (as defined in the SiteMap class var) is called
DefaultSite (and the others are all specialized subclasses of DefaultSite).
&nbsp;It's implementation of DefaultSite&gt;&gt;process: is as follows:<br>
<br>
process: httpRequest<br>
&nbsp;&nbsp;&nbsp; | str docFile doc |<br>
&nbsp;&nbsp;&nbsp; doc _ self relativePath.<br>
&nbsp;&nbsp;&nbsp; (self class cgiMap<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; at: doc<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ifAbsent: []) isNil<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ifFalse: [^ self<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; perform: (self class cgiMap at: doc)].<br>
&nbsp;&nbsp;&nbsp; [docFile _ (FileDirectory on: self docRoot)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; oldFileNamed: doc]<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; on: FileDoesNotExistException<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; do: [:ex | <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; self logError: ex asString.<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ^ self errorPage].<br>
&nbsp;&nbsp;&nbsp; (docFile name endsWith: 'ssp')<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ifTrue: [str _ HTMLformatter evalEmbedded: docFile contents with:
httpRequest.<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; docFile close]<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ifFalse: [str _ docFile].<br>
&nbsp;&nbsp;&nbsp; ^ str<br>
<br>
The implementation of DefaultSite&gt;&gt;relativePath is as follows:<br>
<br>
relativePath<br>
&nbsp;&nbsp;&nbsp; | filePath dir lastChar |<br>
&nbsp;&nbsp;&nbsp; filePath _ httpRequest url copyFrom: 2 to: httpRequest url size.<br>
&nbsp;&nbsp;&nbsp; filePath size &gt; 0<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ifTrue: [lastChar _ filePath last].<br>
&nbsp;&nbsp;&nbsp; filePath _ filePath filePath.<br>
&nbsp;&nbsp;&nbsp; (lastChar = $/<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; or: [filePath = ''])<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ifTrue: [dir _ FileDirectory on: self docRoot , filePath.<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; [(dir fileExists: 'index.html')<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ifTrue: [filePath _ filePath , 'index.html']<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ifFalse: [filePath _ filePath , 'index.htm']]<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; on: Error<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; do: [^ '']].<br>
&nbsp;&nbsp;&nbsp; ^ filePath<br>
<br>
You will notice that all of the above also allows standard cgi-style web
request processing. &nbsp;It also allows SSP (Smalltalk Server Pages, or embedded
Smalltalk code within an html page being served). &nbsp;It also serves static
content. &nbsp;And, it does virtual hosting. &nbsp;And, it all happily lives along
side of Seaside (Seaside, plus static content, plus SSP content, plus virtual
domain hosting, plus a few other bells and whistles).<br>
<br>
Nevin<br>
<br>
<pre class="moz-signature" cols="$mailwrapcol">-- 
Nevin Pratt
Bountiful Baby
<a class="moz-txt-link-freetext" href="http://www.bountifulbaby.com">http://www.bountifulbaby.com</a>
(801) 992-3137
</pre>
<br>
</body>
</html>