<!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. To do this, rather than using the ChieftainModule,
I created a subclass of WAKom, which I call ComancheInterface (for lack of
a better name). It has the following #process: method:<br>
<br>
process: aRequest <br>
"This is the required Comanche method that kicks everything off. <br>
Nothing else works until this method is properly run, and it will <br>
automatically be run by Comanche."<br>
| url |<br>
httpRequest _ aRequest.<br>
url _ httpRequest url.<br>
(url beginsWith: '/seaside/')<br>
ifTrue: [^super process: aRequest].<br>
WebHit logRequest: aRequest.<br>
((url beginsWith: '/secure/')<br>
and: [httpRequest ipString ~= '127.0.0.1'])<br>
ifTrue: [^ self redirectToSecurePort].<br>
(url endsWithAnyOf: MicrosoftRedirects)<br>
ifTrue: [^ self redirectToMicrosoft].<br>
(url endsWithAnyOf: SenderRedirects)<br>
ifTrue: [^ self redirectToSender].<br>
self processMultipartFields: aRequest.<br>
^ self siteManager process: httpRequest<br>
<br>
My three 'redirect' methods are implemented thus:<br>
<br>
redirectToMicrosoft<br>
"So that I can redirect all the NT/XP/2K virii to the originator of the
<br>
problem "<br>
^ httpRequest redirectTo: '<a class="moz-txt-link-freetext" href="http://www.microsoft.com">http://www.microsoft.com</a>'<br>
<br>
<br>
redirectToSecurePort<br>
"In case they hit my secure pages via port 80 instead of port 443"<br>
^ httpRequest redirectTo: '<a class="moz-txt-link-freetext" href="https://">https://</a>' , httpRequest host , '/' , httpRequest
url<br>
<br>
<br>
redirectToSender<br>
"Primarily so that requests from kiddie scripts that are probing the
<br>
system can just get routed back to the originator."<br>
^ 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>
| tok site host |<br>
site _ 'default'.<br>
host _ httpRequest host.<br>
host notNil<br>
ifTrue: [tok _ host findTokens: '.'.<br>
tok size > 1<br>
ifTrue: [site _ tok at: tok size - 1].<br>
tok size = 1<br>
ifTrue: [site _ tok last].<br>
(SiteMap includesKey: site)<br>
ifFalse: [site _ 'default']].<br>
^ (SiteMap at: site) default<br>
<br>
The SiteMap is a class var containing a dictionary. 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. 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). 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).
It's implementation of DefaultSite>>process: is as follows:<br>
<br>
process: httpRequest<br>
| str docFile doc |<br>
doc _ self relativePath.<br>
(self class cgiMap<br>
at: doc<br>
ifAbsent: []) isNil<br>
ifFalse: [^ self<br>
perform: (self class cgiMap at: doc)].<br>
[docFile _ (FileDirectory on: self docRoot)<br>
oldFileNamed: doc]<br>
on: FileDoesNotExistException<br>
do: [:ex | <br>
self logError: ex asString.<br>
^ self errorPage].<br>
(docFile name endsWith: 'ssp')<br>
ifTrue: [str _ HTMLformatter evalEmbedded: docFile contents with:
httpRequest.<br>
docFile close]<br>
ifFalse: [str _ docFile].<br>
^ str<br>
<br>
The implementation of DefaultSite>>relativePath is as follows:<br>
<br>
relativePath<br>
| filePath dir lastChar |<br>
filePath _ httpRequest url copyFrom: 2 to: httpRequest url size.<br>
filePath size > 0<br>
ifTrue: [lastChar _ filePath last].<br>
filePath _ filePath filePath.<br>
(lastChar = $/<br>
or: [filePath = ''])<br>
ifTrue: [dir _ FileDirectory on: self docRoot , filePath.<br>
[(dir fileExists: 'index.html')<br>
ifTrue: [filePath _ filePath , 'index.html']<br>
ifFalse: [filePath _ filePath , 'index.htm']]<br>
on: Error<br>
do: [^ '']].<br>
^ filePath<br>
<br>
You will notice that all of the above also allows standard cgi-style web
request processing. It also allows SSP (Smalltalk Server Pages, or embedded
Smalltalk code within an html page being served). It also serves static
content. And, it does virtual hosting. 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>