Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > BOOK: Professional AngularJS
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
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.
Reply With Quote
The Following 2 Users Say Thank You to tomliao For This Useful Post:
natMille (March 10th, 2016), njho (January 27th, 2016)
  #2 (permalink)  
Old January 26th, 2016, 02:30 PM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2016
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Default Thanks!

Thanks!
Reply With Quote
  #3 (permalink)  
Old March 9th, 2016, 01:41 PM
Registered User
Points: 24, Level: 1
Points: 24, Level: 1 Points: 24, Level: 1 Points: 24, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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!
Reply With Quote
  #4 (permalink)  
Old March 10th, 2016, 10:18 AM
Registered User
Points: 24, Level: 1
Points: 24, Level: 1 Points: 24, Level: 1 Points: 24, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
  #5 (permalink)  
Old October 5th, 2016, 11:21 AM
Registered User
Points: 34, Level: 1
Points: 34, Level: 1 Points: 34, Level: 1 Points: 34, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2016
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank u so much
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 11:57 AM
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 11:41 AM
syntax error only when zxml.js included daddy BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 July 1st, 2006 10:33 PM



All times are GMT -4. The time now is 01:26 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.