pahlers / grunt-connect-http-auth

Http-auth middleware for grunt-connect.
MIT License
1 stars 1 forks source link

no method 'split' #1

Open theherk opened 10 years ago

theherk commented 10 years ago

I cannot seem to get past this error:

Loading "Gruntfile.js" tasks...ERROR
>> TypeError: Object function (Target) {
>>         grunt.task.run([
>>             'configureHttpAuth',
>>             'connect:livereload'
>>         ]);
>>     } has no method 'split'

I am sure I am just being new at this and making a stupid mistake. Or perhaps there is a difference in how things operate from version to version.

Here is my current Gruntfile.js:

/* global module:false */
module.exports = function(grunt) {
    var port = grunt.option('port') || 8000;
    var authRequest = require('grunt-connect-http-auth/lib/utils').authRequest;

    // Project configuration
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        connect: {
            options: {
                port: '8000',
                hostname: '*',
                base: 'presentations'
            },
            livereload: {
                options: {
                    middleware: function (connect) {
                        return [
                            authRequest
                        ];
                    }
                }
            },
            auth: {
                authRealm: 'Presentations',
                authList: ['adam:new']
            }
        },

    });

    // Dependencies
    grunt.loadNpmTasks( 'grunt-contrib-qunit' );
    grunt.loadNpmTasks( 'grunt-contrib-jshint' );
    grunt.loadNpmTasks( 'grunt-contrib-cssmin' );
    grunt.loadNpmTasks( 'grunt-contrib-uglify' );
    grunt.loadNpmTasks( 'grunt-contrib-watch' );
    grunt.loadNpmTasks( 'grunt-contrib-sass' );
    grunt.loadNpmTasks( 'grunt-contrib-connect' );
    grunt.loadNpmTasks( 'grunt-zip' );
    grunt.loadNpmTasks( 'grunt-connect-http-auth' );

    grunt.registerTask( 'serve', function(Target) {
        grunt.task.run([
            'configureHttpAuth',
            'connect:livereload'
        ]);
    });

};

I can do this without auth, but it would be helpful. Am I confused if I am just making a mistake or what. Any ideas?

pahlers commented 10 years ago

Everything looks correct. I don't understand why it tries to execute split, a String operation, on a function (Object).

  grunt.registerTask('serve', function (target) {
    if (target === 'dist') {
      return grunt.task.run([
          'build',
          'open',
          'configureHttpAuth',
          'configureProxies',
          'connect:dist:keepalive'
        ]);
    }

    grunt.task.run([
      'configureHttpAuth',
      'configureProxies',
      'clean:server',
      'concurrent:server',
      'connect:livereload',
      'open',
      'watch'
    ]);
  });

Is Gruntfile.js working without configureHttpAuth in the task 'serve'?

Can you tell me which versions you using (npm list)? Maybe the interface of http-auth changed. I'm using 1.2.9.

Did you mount a folder after modAuth? Maybe that could be the problem.

      livereload: {
        options: {
          middleware: function (connect) {
            return [
              modAuth,
              proxySnippet,
              lrSnippet,
              mountFolder(connect, '.tmp'),
              mountFolder(connect, yeomanConfig.app)
            ];
          }
        }
      },

Last option. In my project I have 'auth' before 'livereload'. It would be stupid when that would be the reason. But if it helps you…

theherk commented 10 years ago

You may have accidentally pointed out an important difference. You say modAuth, but according to the docs I am returning authRequest. What should be returned?

Also, I am using 1.2.9, as well. I will try and reverse the order under connect, but I would love if you could clarify what to return in the middleware.

As an aside, do the default middlewares still get returned, even if overridden or does middlewares need to be returned with authRequest/modAuth?

pahlers commented 10 years ago

My var is called modAuth, but the content is the same. What you doing is correct.

var modAuth = require('grunt-connect-http-auth/lib/utils').authRequest;

Also, I am using 1.2.9, as well. I will try and reverse the order under connect, but I would love if you could clarify what to return in the middleware.

I don't understand your question.

As an aside, do the default middlewares still get returned, even if overridden or does middlewares need to be returned with authRequest/modAuth?

I hope I understand is question correct. Every middleware is adding or removing something to the http request and/or response. Every middleware passing these attributes to the next middleware till all middlewares are done. Your authRequest is not replace the other middlewares, it's just adding basic authentication to the request.