Server not returning some of the files at random #402

Closed
ews opened this Issue Sep 12, 2012 · 16 comments

Comments

Projects
None yet
8 participants
@ews

ews commented Sep 12, 2012

yeoman server (on a new project)

Tons of this on the console

TypeError: Cannot read property 'server' of undefined
at Object.inject (/usr/local/lib/node_modules/yeoman/tasks/server.js:408:28)
at next (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/proto.js:190:15)
at Function.app.handle (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/proto.js:198:3)
at Server.app (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/connect.js:60:31)
at Server.EventEmitter.emit (events.js:91:17)
at HTTPParser.parser.onIncoming (http.js:1795:12)
at HTTPParser.parserOnHeadersComplete as onHeadersComplete
at Socket.socket.ondata (http.js:1692:22)
at TCP.onread (net.js:403:27)
at process.startup.processMakeCallback.process._makeCallback (node.js:248:20)

Line 408 of server.py is var port = res.socket.server.address().port;

Some files not being delivered (output from webkit console)

Request URL:http://localhost:3501/scripts/vendor/bootstrap/bootstrap-carousel.js
Request Method:GET
Status Code:500 Internal Server Error
Request URL:http://localhost:3501/scripts/vendor/bootstrap/bootstrap-button.js
Request Method:GET
Status Code:500 Internal Server Error
[.....] (all in the bootstrap dir, which has correct permissions

Also, when accessing the url individually I can see the files, so this can be related to livereload.js / websockets (?)

@addyosmani

This comment has been minimized.

Show comment
Hide comment
@addyosmani

addyosmani Sep 12, 2012

Member

Could you describe which options you included when running yeoman init?

Member

addyosmani commented Sep 12, 2012

Could you describe which options you included when running yeoman init?

@thvd

This comment has been minimized.

Show comment
Hide comment
@thvd

thvd Sep 12, 2012

I have the same problem as well, and I had all options included.

thvd commented Sep 12, 2012

I have the same problem as well, and I had all options included.

@AtHeartEngineer

This comment has been minimized.

Show comment
Hide comment
@AtHeartEngineer

AtHeartEngineer Sep 13, 2012

Same issue here, and chrome is returning error 500s on all the JS files except for jquery

osx 10.8.2
yeoman v0.9.0
yeoman init y,y,n,n,n

Same issue here, and chrome is returning error 500s on all the JS files except for jquery

osx 10.8.2
yeoman v0.9.0
yeoman init y,y,n,n,n

@thvd

This comment has been minimized.

Show comment
Hide comment
@thvd

thvd Sep 13, 2012

I'm using Ubuntu as my OS:

Linux 3.2.0-30-generic #48-Ubuntu SMP Fri Aug 24 16:52:48 UTC 2012 x86_64 GNU/Linux

thvd commented Sep 13, 2012

I'm using Ubuntu as my OS:

Linux 3.2.0-30-generic #48-Ubuntu SMP Fri Aug 24 16:52:48 UTC 2012 x86_64 GNU/Linux
@everpointer

This comment has been minimized.

Show comment
Hide comment
@everpointer

everpointer Sep 13, 2012

Same here!
osx 10.8.1
yeoman v0.9.0
option: yeoman init ember

work well on apache!

Same here!
osx 10.8.1
yeoman v0.9.0
option: yeoman init ember

work well on apache!

@AtHeartEngineer

This comment has been minimized.

Show comment
Hide comment
@AtHeartEngineer

AtHeartEngineer Sep 14, 2012

Any update on this?? I'm still having the same issue

Any update on this?? I'm still having the same issue

@AtHeartEngineer

This comment has been minimized.

Show comment
Hide comment
@AtHeartEngineer

AtHeartEngineer Sep 14, 2012

in chrome I am getting
Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://localhost:3501/scripts/vendor/cf69c6f2.modernizr.min.js but going to that address it loads fine
Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://localhost:3501/scripts/8ab52a5b.plugins.js same result with this one.

In terminal I am getting

Running "watch" task
Waiting...TypeError: Cannot read property 'server' of undefined
    at Object.inject (/usr/local/lib/node_modules/yeoman/tasks/server.js:408:28)
    at next (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/proto.js:190:15)
    at Function.app.handle (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/proto.js:198:3)
    at Server.app (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/connect.js:60:31)
    at Server.EventEmitter.emit (events.js:91:17)
    at HTTPParser.parser.onIncoming (http.js:1793:12)
    at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:111:23)
    at Socket.socket.ondata (http.js:1690:22)
    at TCP.onread (net.js:403:27)
TypeError: Cannot read property 'server' of undefined
    at Object.inject (/usr/local/lib/node_modules/yeoman/tasks/server.js:408:28)
    at next (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/proto.js:190:15)
    at Function.app.handle (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/proto.js:198:3)
    at Server.app (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/connect.js:60:31)
    at Server.EventEmitter.emit (events.js:91:17)
    at HTTPParser.parser.onIncoming (http.js:1793:12)
    at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:111:23)
    at Socket.socket.ondata (http.js:1690:22)
    at TCP.onread (net.js:403:27)```

in chrome I am getting
Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://localhost:3501/scripts/vendor/cf69c6f2.modernizr.min.js but going to that address it loads fine
Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://localhost:3501/scripts/8ab52a5b.plugins.js same result with this one.

In terminal I am getting

Running "watch" task
Waiting...TypeError: Cannot read property 'server' of undefined
    at Object.inject (/usr/local/lib/node_modules/yeoman/tasks/server.js:408:28)
    at next (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/proto.js:190:15)
    at Function.app.handle (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/proto.js:198:3)
    at Server.app (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/connect.js:60:31)
    at Server.EventEmitter.emit (events.js:91:17)
    at HTTPParser.parser.onIncoming (http.js:1793:12)
    at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:111:23)
    at Socket.socket.ondata (http.js:1690:22)
    at TCP.onread (net.js:403:27)
TypeError: Cannot read property 'server' of undefined
    at Object.inject (/usr/local/lib/node_modules/yeoman/tasks/server.js:408:28)
    at next (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/proto.js:190:15)
    at Function.app.handle (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/proto.js:198:3)
    at Server.app (/usr/local/lib/node_modules/yeoman/node_modules/connect/lib/connect.js:60:31)
    at Server.EventEmitter.emit (events.js:91:17)
    at HTTPParser.parser.onIncoming (http.js:1793:12)
    at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:111:23)
    at Socket.socket.ondata (http.js:1690:22)
    at TCP.onread (net.js:403:27)```

@mklabs

This comment has been minimized.

Show comment
Hide comment
@mklabs

mklabs Sep 14, 2012

Contributor

@sindresorhus It seems that we have an issue on the res.socket.server.adress().port, but it's inconsistent. Most of time it's okay, then on some request we get this issue. If I recall correctly, we need to do this because of the randomized port, internally handled by connect.

@tylershaw Just to check, it would be great if you can try moving that var port = res.socket.server.address().port;, right after this few lines: https://github.com/yeoman/yeoman/blob/travis/cli/tasks/server.js#L423-425. It won't help us understand why we get randomly an undefined res.socket, but at least it should debug you through (and would give us some pointers).

Contributor

mklabs commented Sep 14, 2012

@sindresorhus It seems that we have an issue on the res.socket.server.adress().port, but it's inconsistent. Most of time it's okay, then on some request we get this issue. If I recall correctly, we need to do this because of the randomized port, internally handled by connect.

@tylershaw Just to check, it would be great if you can try moving that var port = res.socket.server.address().port;, right after this few lines: https://github.com/yeoman/yeoman/blob/travis/cli/tasks/server.js#L423-425. It won't help us understand why we get randomly an undefined res.socket, but at least it should debug you through (and would give us some pointers).

@AtHeartEngineer

This comment has been minimized.

Show comment
Hide comment
@AtHeartEngineer

AtHeartEngineer Sep 14, 2012

HA! @mklabs You are a genius! that fixed it.

 return function inject(req, res, next) {


      // build filepath from req.url and deal with index files for trailing `/`
      var filepath = req.url.slice(-1) === '/' ? req.url + 'index.html' : req.url;

      // if ext is anything but .html, let it go through usual connect static
      // middleware.
      if ( path.extname( filepath ) !== '.html' ) {
        return next();
      }
      var port = res.socket.server.address().port;
      // setup some basic headers, at this point it's always text/html anyway
      res.setHeader('Content-Type', connect.static.mime.lookup(filepath));

      // can't use the ideal stream / pipe case, we need to alter the html response
      // by injecting that little livereload snippet
      filepath = path.join(opts.base, filepath.replace(/^\//, ''));
      fs.readFile(filepath, 'utf8', function(e, body) {
        if(e) {
          // go next and silently fail
          return next();
        }

        body = body.replace(/<\/body>/, function(w) {
          return [
            "<!-- yeoman livereload snippet -->",
            "<script>document.write('<script src=\"http://'",
            " + (location.host || 'localhost').split(':')[0]",
            " + ':" + port + "/livereload.js?snipver=1\"><\\/script>')",
            "</script>",
            "",
            w
          ].join('\n');
        });

HA! @mklabs You are a genius! that fixed it.

 return function inject(req, res, next) {


      // build filepath from req.url and deal with index files for trailing `/`
      var filepath = req.url.slice(-1) === '/' ? req.url + 'index.html' : req.url;

      // if ext is anything but .html, let it go through usual connect static
      // middleware.
      if ( path.extname( filepath ) !== '.html' ) {
        return next();
      }
      var port = res.socket.server.address().port;
      // setup some basic headers, at this point it's always text/html anyway
      res.setHeader('Content-Type', connect.static.mime.lookup(filepath));

      // can't use the ideal stream / pipe case, we need to alter the html response
      // by injecting that little livereload snippet
      filepath = path.join(opts.base, filepath.replace(/^\//, ''));
      fs.readFile(filepath, 'utf8', function(e, body) {
        if(e) {
          // go next and silently fail
          return next();
        }

        body = body.replace(/<\/body>/, function(w) {
          return [
            "<!-- yeoman livereload snippet -->",
            "<script>document.write('<script src=\"http://'",
            " + (location.host || 'localhost').split(':')[0]",
            " + ':" + port + "/livereload.js?snipver=1\"><\\/script>')",
            "</script>",
            "",
            w
          ].join('\n');
        });
@mklabs

This comment has been minimized.

Show comment
Hide comment
@mklabs

mklabs Sep 14, 2012

Contributor

haha glad it helped you out.

We still need to figure out why we get that nasty undefined error.

Contributor

mklabs commented Sep 14, 2012

haha glad it helped you out.

We still need to figure out why we get that nasty undefined error.

addyosmani added a commit that referenced this issue Sep 14, 2012

paulirish added a commit that referenced this issue Sep 14, 2012

Merge branch 'master' of github.com:yeoman/yeoman
* 'master' of github.com:yeoman/yeoman:
  Adding server fix for #422, #402
@AtHeartEngineer

This comment has been minimized.

Show comment
Hide comment
@AtHeartEngineer

AtHeartEngineer Sep 14, 2012

Annnnnddddd you guys are awesome. Thanks!

Annnnnddddd you guys are awesome. Thanks!

@thvd

This comment has been minimized.

Show comment
Hide comment
@thvd

thvd Sep 14, 2012

Indeed! But how can i use this fix? Should I wait until Yeoman v1.0 will be released?

thvd commented Sep 14, 2012

Indeed! But how can i use this fix? Should I wait until Yeoman v1.0 will be released?

@sindresorhus

This comment has been minimized.

Show comment
Hide comment
@sindresorhus

sindresorhus Sep 14, 2012

Member

This should be fixed in 0.9.1 which is going to be released very soon.

Member

sindresorhus commented Sep 14, 2012

This should be fixed in 0.9.1 which is going to be released very soon.

@AtHeartEngineer

This comment has been minimized.

Show comment
Hide comment
@AtHeartEngineer

AtHeartEngineer Sep 14, 2012

when i do git pull now, the install.sh file is what the audit.sh file was a few hours ago, and doesn't install anything, just tells you what you have installed and don't have installed. Was this on purpose?

I'm putting this in this thread because I was trying to see if the changes that were made from this thread were merged yet.

when i do git pull now, the install.sh file is what the audit.sh file was a few hours ago, and doesn't install anything, just tells you what you have installed and don't have installed. Was this on purpose?

I'm putting this in this thread because I was trying to see if the changes that were made from this thread were merged yet.

@jorgeramirez

This comment has been minimized.

Show comment
Hide comment
@jorgeramirez

jorgeramirez Sep 15, 2012

Yes. The install.sh has changed, it now audits you on what you need to install in order to start using yeoman see #400 for the discussion that was going on about this.

Yes. The install.sh has changed, it now audits you on what you need to install in order to start using yeoman see #400 for the discussion that was going on about this.

@thvd

This comment has been minimized.

Show comment
Hide comment
@thvd

thvd Sep 15, 2012

Thanks guys for the good work, it's working :)

thvd commented Sep 15, 2012

Thanks guys for the good work, it's working :)

szinya pushed a commit to menthainternet/yeoman that referenced this issue Sep 17, 2014

addyosmani added a commit that referenced this issue Apr 24, 2015

paulirish added a commit that referenced this issue Apr 24, 2015

Merge branch 'master' of github.com:yeoman/yeoman
* 'master' of github.com:yeoman/yeoman:
  Adding server fix for #422, #402
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment