Skip to content
This repository

Middleware static - Properly merge options, allow getOnly to be configured. #482

Closed
wants to merge 1 commit into from

4 participants

Ralph Holzmann TJ Holowaychuk Balazs Nagy Jonathan Ong
Ralph Holzmann

Pretty small change, but I needed getOnly to be false on a recent project, and found that it was hard coded to true. Fixed up options merging and made getOnly configurable.

TJ Holowaychuk
Collaborator

for what? POSTing to a static file etc is kinda weird

Ralph Holzmann

Yeah, I agree it sounds dumb, but we're using some static JSON files as "fixtures" for the unit tests on our framework. So our unit tests would attempt to POST to the static JSON file which would emulate a restful update. No big deal if you dont want to merge it in, but there was still a bug in the way options were being merged, so that's fixed too.

Balazs Nagy

@visionmedia, this fix would be benefical for handling Facebook Canvas authentication, where OAuth tokens come in POST but you should render the page as well, which could be a static file (e.g. with client side mvc)

https://developers.facebook.com/docs/authentication/canvas/

Ralph Holzmann

I'd like to highlight this issue again. I'm trying to set up headless unit tests using PhantomJS for CanJS, but they're failing because we can't use our fixtures with Connect. All I'm asking is that connect acts like other server software where posting to a static file still loads the static file. I dont want to have to comment out lines every time I set up the project. Thanks.

TJ Holowaychuk
Collaborator

it's been broken down into https://github.com/visionmedia/send so now you can do whatever you want, if you're using express there's res.sendfile() which is the same thing with a nicer api

Jonathan Ong
Collaborator

way old. probably belongs in https://github.com/visionmedia/send now if anything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Feb 24, 2012
Ralph Holzmann Middleware static - Properly merge options. Allow getOnly to be confi…
…gured.
5e059f4
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 8 additions and 4 deletions. Show diff stats Hide diff stats

  1. +8 4 lib/middleware/static.js
12 lib/middleware/static.js
@@ -46,16 +46,20 @@ var fs = require('fs')
46 46 * @api public
47 47 */
48 48
  49 +
  50 +
  51 +
49 52 exports = module.exports = function static(root, options){
50   - options = options || {};
  53 + options = utils.merge({
  54 + getOnly : true,
  55 + root : root
  56 + }, options);
51 57
52 58 // root required
53   - if (!root) throw new Error('static() root path required');
54   - options.root = root;
  59 + if (!options.root) throw new Error('static() root path required');
55 60
56 61 return function static(req, res, next) {
57 62 options.path = req.url;
58   - options.getOnly = true;
59 63 send(req, res, next, options);
60 64 };
61 65 };

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.