Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Serving static files, but not from public directory?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Felix E. Klee  
View profile  
 More options Aug 3 2012, 1:07 pm
From: "Felix E. Klee" <felix.k...@inka.de>
Date: Fri, 3 Aug 2012 19:07:08 +0200
Local: Fri, Aug 3 2012 1:07 pm
Subject: Re: [nodejs] Serving static files, but not from public directory?

On Fri, Aug 3, 2012 at 5:16 PM, Tim Caswell <t...@creationix.com> wrote:
> What kind of caching do you want?

Actually it's just one file that needs *caching* and *compression*:

    http://example.com/xyz.js

The other files are just exposed for development (process.env.NODE_ENV
!== 'production'):

    http://example.com/scripts/*.js

And, then I want to provide Socket.IO. Fortunately, the Socket.IO module
is taking care of serving itself.

What is all this? It's an API that users interface with via an object
provided by `xyz.js`. In a way it's similar to the YouTube API. There
you first load some JavaScript, and then you interact with the `YT`
object, to: load a new video, play it, stop it, etc.

The contents of the directory `script` are a bunch of AMD modules. They
are the building blocks of `xyz.js`.

> And are you also talking about conditional http requests (Etag,
> timestamps, 304 responses)? What about range request support?

Nothing complicated - see above. No redirects, no error page, etc.

> A simple filter in front of any off-the-shelf static file server
> should five you 95% of what you want.

I don't want to use a separate file server.

> var staticHandler = require('creationix').static("/", __dirname);

Looks interesting! Reading the source of `static()`...

> Then you'll mount / -> / but only if it ends in ".js" and is not
> app.js.

There are more files that I don't want to serve in `/`. In fact, for
security reasons, I don't want to mount `/` at all...

> If you don't mind caching your files in memory, then just read the
> files to ram (either at startup or on demand) and watch the files for
> changes (if you want to pick up changes) to invalidate your cache.

I see. That's a start for `xyz.js`. I could just use `fs.watchFile`.
Then I also need to think about compression. But perhaps the Nodejitsu
folks take care of that.

> Don't fall into the trap of using a large library that only does 50%
> of what you [...]

OTOH I don't have any special requirements, and so writing my own static
file serving code - while surely instructional - seems like reinventing
the wheel.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.