Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > BOOK: Professional AngularJS
|
BOOK: Professional AngularJS
This is the forum to discuss the Wrox book Professional AngularJS by Valeri Karpov, Diego Netto; ISBN: 978-1-118-83207-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional AngularJS section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 1st, 2015, 12:00 AM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2015
Posts: 1
Thanks: 0
Thanked 2 Times in 1 Post
Default Problem syntax in Gruntfile.js of chapter 2

In the "The Connect Task" section in chapter 2, the author shows the second part of the code in Gruntfile.js as:

Code:
      // [2] Arbitrarily named target
      development: {
        // Target options, overrides task options
        options: {
          middleware: function(connect) {
            return [
              connect.static('app')
            ];
          }
        }
      }
    }
However, when I ran the command "grunt" from command-line, I got a warning saying "Warning: undefined is not a function Use --force to continue." and the program stopped. Then I used "grunt --verbose" command trying to start the program, I can see "middleware=undefined" in the output.

As of this writing, I found a solution to fix the problem. I changed the whole part of middleware code into:
Code:
base: 'app'
, and it worked.

What I don't understand are:

1. Why the original code returned as undefined?

2. As the author mentioned in the book,
Quote:
Because your application files reside inside the app/ directory, you need to tell your development target to serve static assets from that location. You accomplish this be setting the middleware property....
. If all we need is just to let our program to start from the app directory, the base option can provide the same functionality, then why we use middleware instead of base?

Update (solution found):
Just found out why my middleware function is returned as undefined, it was due to that "static" is no longer a part of Connect module. If one wants to use connect.static function, should install "serve-static", and then declare a variable to require serve-static. What I did for the above code after installing serve-static was:
Code:
// Declare a variable to require serve-static, and I declare it outside the gult.initConfig function
var serveStatic = require('serve-static');
.....
.....
      // [2] Arbitrarily named target
      development: {
        // Target options, overrides task options
        options: {
          middleware: function(connect) {
            return [
              serveStatic('app')
            ];
          }
        }
      }
    }

Last edited by tomliao; August 1st, 2015 at 02:23 AM..
The Following 2 Users Say Thank You to tomliao For This Useful Post:
natMille (March 10th, 2016), njho (January 27th, 2016)
 
Old January 26th, 2016, 03:30 PM
Registered User
 
Join Date: Jan 2016
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Default Thanks!

Thanks!
 
Old March 9th, 2016, 02:41 PM
Registered User
 
Join Date: Mar 2016
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default Thank you!

I got it thanks to this!!!

thanks again!
 
Old March 10th, 2016, 11:18 AM
Registered User
 
Join Date: Mar 2016
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default similar fix for getting the gulp to work

Hello,

Just thought I would add that getting the gulp to work is very similar to the suggestions here for the grunt.

Code:
 // [2] Load plug-ins
var $ = require('gulp-load-plugins') ();
//declare the serveStatic variable as you did in the grunt
var serveStatic = require('serve-static');
...
...
...

then

Code:
 // 'connect' task for starting web server
gulp.task('connect', function () {
  var connect = require('connect');
  var app = connect()
    .use(require('connect-livereload') ({ port: 35729 }))
    .use(serveStatic('app')); 
 // .use(serveStatic.directory('app')); 
//the serveStatic.directory line above is not needed comment out or delete it
after doing this my server connected successfully showing the correct formatting and dynamically updating

hope this is helpful
 
Old October 5th, 2016, 11:21 AM
Registered User
 
Join Date: Apr 2016
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank u so much





Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax error in Gruntfile.js (Chapter 1, Step 2) matthiku BOOK: Professional AngularJS 1 May 6th, 2015 06:16 AM
Chapter 5 Node connectserver.js doesnt work cmrobertson BOOK: Beginning Building Mobile Application Development in the Cloud 0 November 24th, 2012 12:57 PM
Chapter 16 - Utils.js mhanson BOOK: JavaScript Programmer's Reference 0 May 25th, 2010 05:03 PM
chapter 7 js error when changing image src grom BOOK: Beginning Ajax with ASP.NET 1 January 3rd, 2008 12:41 PM
syntax error only when zxml.js included daddy BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 July 1st, 2006 10:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.