Zinc as static file server

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
23 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Zinc as static file server

Paul DeBruicker
Hi -

Following these instructions you can make Comanche serve static files
from a local directory while also handling Seaside requests:
http://samadhiweb.com/blog/2011.07.10.seaside.comanche.staticfiles.html

Is there a way to do the same with Zinc and the ZnStaticFileServerDelegate ?

Thanks

Paul
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Zinc as static file server

Paul DeBruicker
Yes.  There is a way.

I uploaded some changes to http://www.squeaksource.com/ZincHTTPComponents that allow Zinc to serve both Seaside requests and static files from the same server adaptor.  


Let me know if they're inappropriate for the ZincHTTPComponents archive


Paul
Reply | Threaded
Open this post in threaded view
|

Re: Zinc as static file server

Sven Van Caekenberghe
Hi Paul,

On 20 Apr 2012, at 02:13, Paul DeBruicker wrote:

> Yes.  There is a way.
>
> I uploaded some changes to http://www.squeaksource.com/ZincHTTPComponents
> that allow Zinc to serve both Seaside requests and static files from the
> same server adaptor.  
>
>
> Let me know if they're inappropriate for the ZincHTTPComponents archive
>
>
> Paul

Thanks for this contribution, I think it is really useful.

I did some merging and some small changes (like making wwwRootDirectory a variable).
So it would be best to update.

Do you have a blog or could you pubish a short writeup of how to use this as you envisioned it ?

Thanks again.

Regards,

Sven


--
Sven Van Caekenberghe
http://stfx.eu
Smalltalk is the Red Pill




_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Zinc as static file server

Paul DeBruicker
Hi Sven,

I don't have a blog and I'm not doing anything sophisticated with it.
It just seems an easier way to serve  static files than messing with
Apache or Nginx for development purposes.   But I will try find the time
to write something up.

Thanks for your upgrades.  I modified the interface so now you can do:

ZnZincStaticServerAdaptor startOn: 8080 andServeFilesFrom: '/var/www/'



I uploaded the revised Zinc-Seaside package.


Paul



On 04/20/2012 02:09 AM, Sven Van Caekenberghe wrote:

> Hi Paul,
>
> On 20 Apr 2012, at 02:13, Paul DeBruicker wrote:
>
>> Yes.  There is a way.
>>
>> I uploaded some changes to http://www.squeaksource.com/ZincHTTPComponents
>> that allow Zinc to serve both Seaside requests and static files from the
>> same server adaptor.
>>
>>
>> Let me know if they're inappropriate for the ZincHTTPComponents archive
>>
>>
>> Paul
>
> Thanks for this contribution, I think it is really useful.
>
> I did some merging and some small changes (like making wwwRootDirectory a variable).
> So it would be best to update.
>
> Do you have a blog or could you pubish a short writeup of how to use this as you envisioned it ?
>
> Thanks again.
>
> Regards,
>
> Sven
>
>
> --
> Sven Van Caekenberghe
> http://stfx.eu
> Smalltalk is the Red Pill
>
>
>
>
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Zinc as static file server

Paul DeBruicker
I added  the ability to specify Cache-Control headers for static files
served by Zinc and added an API to the ZnZincStaticServerAdaptor that
allows you to use the defaults or provide a custom specification.




On 04/20/2012 04:56 PM, Paul DeBruicker wrote:

> Hi Sven,
>
> I don't have a blog and I'm not doing anything sophisticated with it. It
> just seems an easier way to serve static files than messing with Apache
> or Nginx for development purposes. But I will try find the time to write
> something up.
>
> Thanks for your upgrades. I modified the interface so now you can do:
>
> ZnZincStaticServerAdaptor startOn: 8080 andServeFilesFrom: '/var/www/'
>
>
>
> I uploaded the revised Zinc-Seaside package.
>
>
> Paul
>
>
>
> On 04/20/2012 02:09 AM, Sven Van Caekenberghe wrote:
>> Hi Paul,
>>
>> On 20 Apr 2012, at 02:13, Paul DeBruicker wrote:
>>
>>> Yes. There is a way.
>>>
>>> I uploaded some changes to
>>> http://www.squeaksource.com/ZincHTTPComponents
>>> that allow Zinc to serve both Seaside requests and static files from the
>>> same server adaptor.
>>>
>>>
>>> Let me know if they're inappropriate for the ZincHTTPComponents archive
>>>
>>>
>>> Paul
>>
>> Thanks for this contribution, I think it is really useful.
>>
>> I did some merging and some small changes (like making
>> wwwRootDirectory a variable).
>> So it would be best to update.
>>
>> Do you have a blog or could you pubish a short writeup of how to use
>> this as you envisioned it ?
>>
>> Thanks again.
>>
>> Regards,
>>
>> Sven
>>
>>
>> --
>> Sven Van Caekenberghe
>> http://stfx.eu
>> Smalltalk is the Red Pill
>>
>>
>>
>>
>> _______________________________________________
>> seaside mailing list
>> [hidden email]
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Zinc as static file server

Sven Van Caekenberghe
Hi Paul,

On 12 May 2012, at 02:57, Paul DeBruicker wrote:

> I added  the ability to specify Cache-Control headers for static files served by Zinc and added an API to the ZnZincStaticServerAdaptor that allows you to use the defaults or provide a custom specification.

Thanks for the contribution (again).

Yes, this is useful, having an expiration time per mime-type seems a bit heavy, but OK.

BTW, we (or I) definitively need to add If-Modified-Since and 304 Not Modified behavior to  ZnZincStaticServerAdaptor.

And I know that you know, but let me repeat that in production situations you definitively have to let apache or nginx serve the statis files, to take load of Seaside.

Your hack in ZnSeasideStaticServerAdaptorDelegate>>#handleRequest: lets Seaside first try and make an error before you consider static file serving, this almost defeats the purpose of not doing it by Seaside itself. Just a hunch, I haven't tested or benchmarked this.

But I know you want this for easier development setup, and it is instructive code for others as well.

Thanks again,

Sven




--
Sven Van Caekenberghe
http://stfx.eu
Smalltalk is the Red Pill




_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Zinc as static file server

Paul DeBruicker
On 05/12/2012 12:52 AM, Sven Van Caekenberghe wrote:
> Thanks for the contribution (again).
>

You're welcome.  Thanks for doing the bulk of the work.


> Yes, this is useful, having an expiration time per mime-type seems a bit heavy, but OK.
>

I figured that since the mimeType had already been figured out in the
#responseForFileNamed: method to just use it.  I'm happy for any revisions.

> BTW, we (or I) definitively need to add If-Modified-Since and 304 Not Modified behavior to  ZnZincStaticServerAdaptor.
>

OK.  I added that to the version I just uploaded.

> And I know that you know, but let me repeat that in production situations you definitively have to let apache or nginx serve the statis files, to take load of Seaside.
>

Yes definitely.

> Your hack in ZnSeasideStaticServerAdaptorDelegate>>#handleRequest: lets Seaside first try and make an error before you consider static file serving, this almost defeats the purpose of not doing it by Seaside itself. Just a hunch, I haven't tested or benchmarked this.
>

Does Seaside have the ability to serve files from disk without loading
them into a WAFileLibrary?  I couldn't figure that out, or gave up
before trying really.  I edit all my CSS and JS in emacs and its a pain
to reload after saving/committing.  And for my use case the performance
is fine.

> But I know you want this for easier development setup, and it is instructive code for others as well.
>

Its certainly a niche market/product.


> Thanks again,
>
> Sven

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Zinc as static file server

Sven Van Caekenberghe

On 12 May 2012, at 19:17, Paul DeBruicker wrote:

>> BTW, we (or I) definitively need to add If-Modified-Since and 304 Not Modified behavior to ZnZincStaticServerAdaptor.
>>
>
> OK.  I added that to the version I just uploaded.

I'll have a look later on (I have little time this weekend).

We also need at least one simple test (another one of Marcus' quotes; if there is no actively run test, it does not exist). We just need an extra version of #testIfModifiedSinceNotModified directly on a local server, it will require some setup, be it should be doable.

>> And I know that you know, but let me repeat that in production situations you definitively have to let apache or nginx serve the statis files, to take load of Seaside.
>>
>
> Yes definitely.
>
>> Your hack in ZnSeasideStaticServerAdaptorDelegate>>#handleRequest: lets Seaside first try and make an error before you consider static file serving, this almost defeats the purpose of not doing it by Seaside itself. Just a hunch, I haven't tested or benchmarked this.
>
> Does Seaside have the ability to serve files from disk without loading them into a WAFileLibrary?  I couldn't figure that out, or gave up before trying really.  I edit all my CSS and JS in emacs and its a pain to reload after saving/committing.  And for my use case the performance is fine.

Yes, your use case is perfectly valid.

Sven

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Zinc as static file server

Sven Van Caekenberghe
Paul,

On 12 May 2012, at 23:59, Sven Van Caekenberghe wrote:

> I'll have a look later on (I have little time this weekend).
>
> We also need at least one simple test (another one of Marcus' quotes; if there is no actively run test, it does not exist). We just need an extra version of #testIfModifiedSinceNotModified directly on a local server, it will require some setup, be it should be doable.

I integrated your changes and added 3 tests:

---

Name: Zinc-HTTP-SvenVanCaekenberghe.275
Author: SvenVanCaekenberghe
Time: 14 May 2012, 10:59:51 am
UUID: 94f2451b-b7e0-4d74-866b-d55b01c98ed9
Ancestors: Zinc-HTTP-PaulDeBruicker.274

refactored ZnStaticFileServerDelegate a bit:
- store expiration times as seconds in #defaultMimeTypeExpiration & #mimeTypeExpiration map
- add not only Cache-Control but Expires header as well
- removed unused #responseForFile:
fixed a bug in ZnMessage>>#clearEntity (didn't #close streaming entities with HEAD requests)

---

Name: Zinc-Tests-SvenVanCaekenberghe.142
Author: SvenVanCaekenberghe
Time: 14 May 2012, 11:11:41 am
UUID: 9f8498a3-c576-4844-a0f5-bafc5c5cbeca
Ancestors: Zinc-Tests-SvenVanCaekenberghe.141

added ZnStaticFileServerDelegateTests for
- expiration
- cache-control
- if-modified-since, not-modified

---

Have a look and tell me what you think.

Sven


--
Sven Van Caekenberghe
http://stfx.eu
Smalltalk is the Red Pill




_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Zinc as static file server

Philippe Marschall
In reply to this post by Paul DeBruicker
On Sat, May 12, 2012 at 7:17 PM, Paul DeBruicker <[hidden email]> wrote:

> On 05/12/2012 12:52 AM, Sven Van Caekenberghe wrote:
>>
>> Thanks for the contribution (again).
>>
>
> You're welcome.  Thanks for doing the bulk of the work.
>
>
>
>> Yes, this is useful, having an expiration time per mime-type seems a bit
>> heavy, but OK.
>>
>
> I figured that since the mimeType had already been figured out in the
> #responseForFileNamed: method to just use it.  I'm happy for any revisions.
>
>
>> BTW, we (or I) definitively need to add If-Modified-Since and 304 Not
>> Modified behavior to  ZnZincStaticServerAdaptor.
>>
>
> OK.  I added that to the version I just uploaded.
>
>
>> And I know that you know, but let me repeat that in production situations
>> you definitively have to let apache or nginx serve the statis files, to take
>> load of Seaside.
>>
>
> Yes definitely.
>
>
>> Your hack in ZnSeasideStaticServerAdaptorDelegate>>#handleRequest: lets
>> Seaside first try and make an error before you consider static file serving,
>> this almost defeats the purpose of not doing it by Seaside itself. Just a
>> hunch, I haven't tested or benchmarked this.
>>
>
> Does Seaside have the ability to serve files from disk without loading them
> into a WAFileLibrary?  I couldn't figure that out, or gave up before trying
> really.  I edit all my CSS and JS in emacs and its a pain to reload after
> saving/committing.  And for my use case the performance is fine.

You can write a request handler that writes on the response stream.

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Zinc as static file server

Dave
In reply to this post by Paul DeBruicker
Paul DeBruicker wrote
Hi Sven,

I don't have a blog and I'm not doing anything sophisticated with it.
It just seems an easier way to serve  static files than messing with
Apache or Nginx for development purposes.   But I will try find the time
to write something up.

Thanks for your upgrades.  I modified the interface so now you can do:

ZnZincStaticServerAdaptor startOn: 8080 andServeFilesFrom: '/var/www/'



I uploaded the revised Zinc-Seaside package.


Paul
Hi Paul,
startOn: andServeFilesFrom: does not exist anymore, right?
I guess it's useful Seaside could serve also static files in a development environment.

Dave
Reply | Threaded
Open this post in threaded view
|

Re: Zinc as static file server

Paul DeBruicker
On 09/04/2013 03:15 PM, Dave wrote:

> Paul DeBruicker wrote
>> Hi Sven,
>>
>> I don't have a blog and I'm not doing anything sophisticated with it.
>> It just seems an easier way to serve  static files than messing with
>> Apache or Nginx for development purposes.   But I will try find the time
>> to write something up.
>>
>> Thanks for your upgrades.  I modified the interface so now you can do:
>>
>> ZnZincStaticServerAdaptor startOn: 8080 andServeFilesFrom: '/var/www/'
>>
>>
>>
>> I uploaded the revised Zinc-Seaside package.
>>
>>
>> Paul
>
> Hi Paul,
> startOn: andServeFilesFrom: does not exist anymore, right?
> I guess it's useful Seaside could serve also static files in a development
> environment.
>
> Dave
>
>


Yeah its on the class side of ZnZincStaticServerAdaptor



>
> --
> View this message in context: http://forum.world.st/Zinc-as-static-file-server-tp4571413p4706558.html
> Sent from the Seaside General mailing list archive at Nabble.com.
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Zinc as static file server

Dave
Paul DeBruicker wrote
>
> Hi Paul,
> startOn: andServeFilesFrom: does not exist anymore, right?
> I guess it's useful Seaside could serve also static files in a development
> environment.
>
> Dave
>
>


Yeah its on the class side of ZnZincStaticServerAdaptor
You are right, I supposed it was on Zinc packages, so I upgraded Zinc only, instead I have to update Seaside.
Thanks
Dave
Reply | Threaded
Open this post in threaded view
|

Re: Zinc as static file server

Dave
In reply to this post by Paul DeBruicker
Paul DeBruicker wrote
> Hi Paul,
> startOn: andServeFilesFrom: does not exist anymore, right?
> I guess it's useful Seaside could serve also static files in a development
> environment.
>
> Dave
>
>


Yeah its on the class side of ZnZincStaticServerAdaptor
Hi Paul,

I can't make it work :-)

I launched ZnZincStaticServerAdaptor startOn: 8080 andServeFilesFrom: '/testDir/'

and I'm wondering if /testDir is relative, absolute (other?)
I created testDir under the location of my image then I created in / but both times when I point the browser on http://localhost:8080/testDir/ I receive a "Not Found"

TIA
Dave
Reply | Threaded
Open this post in threaded view
|

Re: Zinc as static file server

Paul DeBruicker
On 09/06/2013 10:58 AM, Dave wrote:

> Hi Paul,
>
> I can't make it work :-)
>
> I launched ZnZincStaticServerAdaptor startOn: 8080 andServeFilesFrom:
> '/testDir/'
>
> and I'm wondering if /testDir is relative, absolute (other?)
> I created testDir under the location of my image then I created in / but
> both times when I point the browser on http://localhost:8080/testDir/ I
> receive a "Not Found"
>
> TIA
> Dave
>
>

Its just a path so could be absolute or relative.  Using '/testDir'
makes it look at the root of your filesystem for a directory named
'testDir'.  If you used 'testDir' rather than '/testDir' then it'd look
in the image directory.


Who owns '/testDir' and can your Pharo process read from there?

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Zinc as static file server

Paul DeBruicker
In reply to this post by Dave
Oh and I don't think it will give a directory listing.  Not sure but you
might stick a file in that testDir and see if you can access it.





On 09/06/2013 10:58 AM, Dave wrote:

> Paul DeBruicker wrote
>>> Hi Paul,
>>> startOn: andServeFilesFrom: does not exist anymore, right?
>>> I guess it's useful Seaside could serve also static files in a
>>> development
>>> environment.
>>>
>>> Dave
>>>
>>>
>>
>>
>> Yeah its on the class side of ZnZincStaticServerAdaptor
>
> Hi Paul,
>
> I can't make it work :-)
>
> I launched ZnZincStaticServerAdaptor startOn: 8080 andServeFilesFrom:
> '/testDir/'
>
> and I'm wondering if /testDir is relative, absolute (other?)
> I created testDir under the location of my image then I created in / but
> both times when I point the browser on http://localhost:8080/testDir/ I
> receive a "Not Found"
>
> TIA
> Dave
>
>
>
>
> --
> View this message in context: http://forum.world.st/Zinc-as-static-file-server-tp4571413p4706967.html
> Sent from the Seaside General mailing list archive at Nabble.com.
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Zinc as static file server

Dave
Paul DeBruicker wrote
Oh and I don't think it will give a directory listing.  Not sure but you
might stick a file in that testDir and see if you can access it.
Same response. But is testDir to be created under the image?
Dave
Reply | Threaded
Open this post in threaded view
|

Re: Zinc as static file server

Dave
In reply to this post by Paul DeBruicker
Sorry I haven't seen this message.
Thanks
Dave

Paul DeBruicker wrote
On 09/06/2013 10:58 AM, Dave wrote:

> Hi Paul,
>
> I can't make it work :-)
>
> I launched ZnZincStaticServerAdaptor startOn: 8080 andServeFilesFrom:
> '/testDir/'
>
> and I'm wondering if /testDir is relative, absolute (other?)
> I created testDir under the location of my image then I created in / but
> both times when I point the browser on http://localhost:8080/testDir/ I
> receive a "Not Found"
>
> TIA
> Dave
>
>

Its just a path so could be absolute or relative.  Using '/testDir'
makes it look at the root of your filesystem for a directory named
'testDir'.  If you used 'testDir' rather than '/testDir' then it'd look
in the image directory.


Who owns '/testDir' and can your Pharo process read from there?

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Zinc as static file server

Dave
In reply to this post by Paul DeBruicker
Paul DeBruicker wrote
Oh and I don't think it will give a directory listing.  Not sure but you
might stick a file in that testDir and see if you can access it.
No way.

* I created testDir under the image file.
* The script is ZnZincStaticServerAdaptor startOn: 8080 andServeFilesFrom: 'testDir'.
* I put a file image.jpg under testDir
* I point the browser at http://localhost:8080/image.jpg

Response: "Not Found /testDir/image.jpg"

Davide
Reply | Threaded
Open this post in threaded view
|

Re: Zinc as static file server

Dave
Got it!
I was wrong, I pointed the browser to http://localhost:8080/testDir/image.jpg/ instead of http://localhost:8080/image.jpg/
Eventually I dig into the code and I discovered debugging ZnStaticFileServerDelegate>>actualFilenameFor:

Sorry to have bugged you.
Dave

Dave wrote
Paul DeBruicker wrote
Oh and I don't think it will give a directory listing.  Not sure but you
might stick a file in that testDir and see if you can access it.
No way.

* I created testDir under the image file.
* The script is ZnZincStaticServerAdaptor startOn: 8080 andServeFilesFrom: 'testDir'.
* I put a file image.jpg under testDir
* I point the browser at http://localhost:8080/image.jpg

Response: "Not Found /testDir/image.jpg"

Davide
12