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

Server not returning some of the files at random #402

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

Server not returning some of the files at random #402

ews opened this issue Sep 12, 2012 · 16 comments

Comments

@ews
Copy link

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
Copy link
Member

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

@thvd
Copy link

thvd commented Sep 12, 2012

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

@AtHeartEngineer
Copy link

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
Copy link

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
Copy link

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

work well on apache!

@AtHeartEngineer
Copy link

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

@AtHeartEngineer
Copy link

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
Copy link
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
Copy link

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
Copy link
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
* 'master' of github.com:yeoman/yeoman:
  Adding server fix for #422, #402
@AtHeartEngineer
Copy link

Annnnnddddd you guys are awesome. Thanks!

@thvd
Copy link

thvd commented Sep 14, 2012

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

@sindresorhus
Copy link
Member

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

@AtHeartEngineer
Copy link

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
Copy link

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
Copy link

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
* '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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants