Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Static provider. Max age setting publishing. #291

Closed
1602 opened this Issue · 7 comments

4 participants

@1602

Would be great to have maxAge setting accesible to modifying after middleware assigning. For example, when I use it with express, I want to set it to 0 for development env and 86400000 for production environment, but, AFAIK env-specific settings applied after middleware chain building.

Thanks,
Anatoliy

@papandreou

The easiest thing is to branch out into separate app.configure blocks when you get to the point in your middleware stack where you want to serve static files. Most likely there'll be greater differences between the two than just the maxAge setting. For instance I usually have the connectGzip running in production mode, and a more informative error handler in development mode:

app.configure(function () {
    // Common setup ...
});

app.configure('production', function () {
    app.use('/static', connectGzip.staticGzip(__dirname + '/../http-pub-production', {maxAge: 365 * 24 * 60 * 60 * 1000}));
    app.use(express.errorHandler());
});

app.configure('development', function () {
    app.use(express.static(__dirname + '/../http-pub-dev'));
    app.use(express.errorHandler({dumpExceptions: true, showStack: true}));
});

Hope that makes sense :)

Best regards,
Papandreou

@1602

But what if I want to use static middleware before all others? Do not want to send cookies for static files, for example.

@papandreou

Then you can have more configure blocks below static. You're not limited to one per environment.

Sorry for just assuming that you're also using Express, by why wouldn't you :)

@1602

Yep, I know that it is possible, just wanted more clean solution. To be more specific, I use not pure express, I'm developing RailwayJS: ROR-like mvc framework based on ExpressJS. Wanted to implement best rails practicies, or even improve them.

So in my case I have separate file config/environment.coffee that contains

app.configure () ->
    // Common setup ...

And few env-specific files with env-sections, for example: config/environments/production.coffee

app.configure 'production', () ->
    // prd settings

Of cource I can put app.configure 'production' section into base env settings, but it's dirty solution :) Even better separate middleware chaining and configuration. It can be done with two-lines patch and will connect static module more transparent for configuring.

@tj
Owner
tj commented

copying rails wont work well for node, though I understand what you want here, I don't think it's overly practical though because we really could expose the settings for all middleware then but it would get quite ugly

@1602

Why do you think rails won't work well for node? Basic idea is to provide tool for fast web app development. It's independent on platform.

@tj
Owner
tj commented

for sure, but javascript + async won't ever be as "nice". geddy tried and it didn't go to well, but that market is always there I suppose if it can be done properly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.