<div>Please correct me if I am wrong, but this still serves the files through the image, only now you are imposing the overhead of first reading the file from the hard drive. This will slow things down, not speed them up, but perhaps your aim is to conserve RAM used by the image? (But of course, loading the files into the image will temporarily increase in-memory image size, and since every request will create load its own set of files from the hard drive, this could drive memory usage way up depending on how many requests are being served.</div>

<div>Am I interpreting this correctly?</div>
<div> </div>
<div>John<br><br></div>
<div class="gmail_quote">On Tue, Oct 26, 2010 at 1:16 PM, Tony Fleig <span dir="ltr">&lt;<a href="mailto:tony.fleig@gmail.com">tony.fleig@gmail.com</a>&gt;</span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">I want to serve CSS and Javascript files from an on-disk directory (i.e. not using WAFileLibrary) and also not using Apache. 
<div><br></div>
<div>I have JQuery CSS files that reference a large number of image files from an images subdirectory. When these files are imported into a WAFileLibrary, the image filenames are changed and of course there are no subdirectories. Changing the original css file to accommodate this is not practical as I expect to receive new ones periodically and then would have to do it all over again.</div>

<div><br></div>
<div>I am attracted by the easy deployment of Seaside apps when Apache is not involved and for the few files involved it doesn&#39;t seem to me that Apache is warranted, especially during development of the site.</div>
<div><br></div>
<div>I could find no information on the right way to do this, so I subclassed WAServerAdaptor as shown below.</div>
<div><br></div>
<div>With these modifications, If the URL received from the browser&#39;s path begins with /static, then files are served from a specified directory. Otherwise, the request is passed on (eventually) to WADispatcher as normal.</div>

<div><br></div>
<div>This works for me, but I have no idea as to whether there is an easier or better way or if there is a feature to allow this that I just did not find.</div>
<div><br></div>
<div>I am coming back to Smalltalk after many years and I am definitely a bit rusty, so any criticism of the code will also be greatly appreciated.</div>
<div><br></div>
<div>Regards,</div>
<div>TF</div>
<div><br></div>
<div><br></div>
<div>
<div>&#39;From Pharo1.1 of 17 July 2010 [Latest update: #11411] on 26 October 2010 at 10:08:40 am&#39;!</div>
<div>WAComancheAdaptor subclass: #TFComancheAdaptor</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>instanceVariableNames: &#39;staticDirectory staticPathPart&#39;</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>classVariableNames: &#39;&#39;</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>poolDictionaries: &#39;&#39;</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>category: &#39;TFStuff&#39;!</div>
<div><br></div>
<div>!TFComancheAdaptor methodsFor: &#39;as yet unclassified&#39; stamp: &#39;TF 10/26/2010 08:58&#39;!</div>
<div>defaultStaticDirectory</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>^ FileDirectory default pathName! !</div>
<div><br></div>
<div>!TFComancheAdaptor methodsFor: &#39;as yet unclassified&#39; stamp: &#39;TF 10/26/2010 08:59&#39;!</div>
<div>defaultStaticPathPart</div>
<div><br></div>
<div><span style="WHITE-SPACE: pre-wrap"></span>^ &#39;static&#39;! !</div>
<div><br></div>
<div>!TFComancheAdaptor methodsFor: &#39;as yet unclassified&#39; stamp: &#39;TF 10/26/2010 09:55&#39;!</div>
<div>process: aNativeRequest</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>&quot;Serve static files from a specified directory if the URL path begins with a specified name.</div>
<div><span style="WHITE-SPACE: pre-wrap"></span></div>
<div><span style="WHITE-SPACE: pre-wrap"></span>The default staticDirectory is the current directory (nominally the Seaside resources directory)</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>and the default static path part is &#39;static&#39;. Thus, if the client requests</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>&#39;<a href="http://localhost:8080/static/css/xyz.css" target="_blank">http://localhost:8080/static/css/xyz.css</a>&#39; and the Seaside resources directory is</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>&#39;/home/user1/Seaside.app/Contents/Resources&#39;, the file returned will be</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>&#39;/home/user1/Seaside.app/Contents/Resources/static/css/xyz.css&#39;.</div>
<div><span style="WHITE-SPACE: pre-wrap"></span></div>
<div><span style="WHITE-SPACE: pre-wrap"></span>Requests whose path does not begin with the static path part are unaffected, i.e. they are</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>processed by the WAComancheAdapter as normal.&quot;</div>
<div><br></div>
<div><span style="WHITE-SPACE: pre-wrap"></span>| context pathParts fullFilePath method response |</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>pathParts := aNativeRequest pathParts.</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>pathParts size &gt; 1 ifTrue: [</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>(pathParts at: 1) = self staticPathPart ifTrue: [</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>method := aNativeRequest method.</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>(#(#GET #POST) includes: method) ifFalse: [^nil].</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>fullFilePath := self staticDirectory,aNativeRequest url. </div>
<div><span style="WHITE-SPACE: pre-wrap"></span>(FileStream isAFileNamed: fullFilePath) ifFalse: [^nil].</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>^HttpResponse </div>
<div><span style="WHITE-SPACE: pre-wrap"></span>fromStream: (StandardFileStream readOnlyFileNamed: fullFilePath).</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>]<span style="WHITE-SPACE: pre-wrap"> </span></div>
<div><span style="WHITE-SPACE: pre-wrap"></span>] .</div>
<div><br></div>
<div><span style="WHITE-SPACE: pre-wrap"></span>^ self processResponse: (super process: aNativeRequest)</div>
<div>! !</div>
<div><br></div>
<div>!TFComancheAdaptor methodsFor: &#39;as yet unclassified&#39; stamp: &#39;TF 10/26/2010 09:54&#39;!</div>
<div>processResponse: aResponse</div>
<div><br></div>
<div><span style="WHITE-SPACE: pre-wrap"></span>&quot;Ensures that we get the HttpAdaptor&#39;s standard notFound error</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>return, rather than the one line of text/plain that is returned by WADispatcher.&quot;<span style="WHITE-SPACE: pre-wrap"> </span></div>
<div><span style="WHITE-SPACE: pre-wrap"></span></div>
<div><span style="WHITE-SPACE: pre-wrap"></span>aResponse status = #notFound</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>ifTrue: [ ^nil ]</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>ifFalse: [^aResponse]</div>
<div>! !</div>
<div><br></div>
<div>!TFComancheAdaptor methodsFor: &#39;as yet unclassified&#39; stamp: &#39;TF 10/26/2010 08:52&#39;!</div>
<div>staticDirectory</div>
<div><br></div>
<div><span style="WHITE-SPACE: pre-wrap"></span>staticDirectory isNil ifTrue: [ staticDirectory := self defaultStaticDirectory ].</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>^ staticDirectory! !</div>
<div><br></div>
<div>!TFComancheAdaptor methodsFor: &#39;as yet unclassified&#39; stamp: &#39;TF 10/26/2010 08:57&#39;!</div>
<div>staticPathPart</div>
<div><span style="WHITE-SPACE: pre-wrap"></span></div>
<div><span style="WHITE-SPACE: pre-wrap"></span>staticPathPart isNil ifTrue: [ staticPathPart := self defaultStaticPathPart ].</div>
<div><span style="WHITE-SPACE: pre-wrap"></span>^ staticPathPart! !</div></div>
<div><br></div><br>_______________________________________________<br>seaside mailing list<br><a href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a><br><a href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside" target="_blank">http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><a href="http://john-mckeon.us/" target="_blank">http://john-mckeon.us</a><br>