Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example in README giving roots as only parameter does not work #4

Closed
joakimbeng opened this issue Mar 7, 2014 · 2 comments
Closed

Comments

@joakimbeng
Copy link

This example:

gulp.task('serve-build', serve(['public', 'build']));

Does not work. It results in 403 Forbidden on every request.

I think it's this line that's causing the problem. There should be a check if parameter is array...

@morganesque
Copy link
Contributor

Yes typeof returns object for arrays and so this test typeof config !== 'object' misses any arrays that have been passed and the next line will therefore clobber them.

Seems like you've got 4 possibilities you want to catch and you want to end up with config being an object and config.root always being an array. So (this might be a bit long winded but) how about this:

    /*
        1. If they've passed a string.   
    */     
    if (typeof config === 'string') {
      config = {root:[config]};
    }

    /*
        2. If they've passed an array.   
    */     
    if (Array.isArray(config))
    {
      config = {root: config}; 
    }

    /*
        3. If they've passed an object but not specified root.
    */     
    if (!config.root) {
      config.root = ['.'];
    }

    /*
        4. If they've passed an object but specified root as a string.
    */     
    if (typeof config.root === 'string') {
      config.root = [config.root];
    }

morganesque added a commit to morganesque/gulp-serve that referenced this issue Mar 18, 2014
I've explained a bit more in this comment: nkt#4 (comment)
@nkt
Copy link
Owner

nkt commented Mar 18, 2014

Merged pull, updated version. @morganesque thanks!

@nkt nkt closed this as completed Mar 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants