krakenjs / express-enrouten

An express route initialization and configuration module.
Other
172 stars 38 forks source link

Doesn't work, doesn't load a page. A browser just freezes in the middle of a request. #42

Closed wzup closed 10 years ago

wzup commented 10 years ago

The module doesn't allow to load a page. When I enable it as writtent in your manual it doesn't load a page. The browser just freezes in the middle of the request. No errors, no any additional info, just freezes. Here's my index.js of a krakenjs application. No any other alternations of the default kraken.js app is made:

'use strict';

var kraken = require('kraken-js'),
    app = require('express')(),
    db = require('./lib/database'),
    options = {
        onconfig: function (config, next) {
            //any config setup/overrides here
            db.config(config.get('databaseConfig'));

            next(null, config);
        }
    },
    port = process.env.PORT || 8000;

// Here I require enrouten:
var enrouten = require('express-enrouten');

// Here I configure it:
app.use(enrouten({
    routes: [
        { path: '/',    method: 'GET', handler: require('./controllers/index') },
        { path: '/foo', method: 'GET', handler: require('./controllers/foo') }
    ]
}));
app.use(kraken(options));

app.listen(port, function (err) {
    console.log('[%s] Listening on http://localhost:%d', app.settings.env, port);
});

Please write how to configure this module right way. You didin't provide enough info. It doesn't work if you include it in your code as written in your manual.

totherik commented 10 years ago

Hey @wzup, you don't need to use express-enrouten directly if you use kraken-js, as kraken already includes express-enrouten as the application's router, so you can accomplish what you're looking for in a few ways, but the easiest would be to customize settings for the already configured enrouten middleware, either in config:

config.json

{
  "middleware": {
    "router": {
        "module": {
          "arguments": [{
            "routes": [
               { "path": "/",    "method": "GET", "handler": "require:./controllers/index" },
               { "path": "/foo", "method": "GET", "handler": "require:./controllers/foo" }
            ]
          }]
    }
  }
}

or in code:

// index.js
// ...
options = {
        onconfig: function (config, next) {
            //any config setup/overrides here
            db.config(config.get('databaseConfig'));
            config.set('middleware:router:module:arguments', [{
                routes: [
                    { path: '/',    method: 'GET', handler: require('./controllers/index') },
                    { path: '/foo', method: 'GET', handler: require('./controllers/foo') }
                ]
            }]);
            next(null, config);
        }
    },
// ...

I just tested with both configurations and they worked without issue.

wzup commented 10 years ago

Unfortunately, it doesn't work. I must commit that the issue still for some reason remains. I did as you wrote in your answer in a brand new krakenjs application. And when I do page reload http://localhost:8000/ the browser just freezes - it tries to load the page but cannot finish it. Then after some time I get chrome error page and it says ERR_EMPTY_RESPONSE.

localhost_8000

I'm on Windows 7 64bit if it matters. Why it happens? Where may be the issue?

aredridel commented 10 years ago

This is now on a completely freshly generated app?

wzup commented 10 years ago

@aredridel Yes, on a completely freshly generated app. Here are my steps:

  1. In a separate cmd window I start MongoDB:

C:\Users\admin>mongod --dbpath C:\MongoDB\data\db

  1. In the next cmd window I generate a karakenjs app:
C:\sbox>yo kraken helloworld

     ,'""`.
hh  / _  _ \
    |(@)(@)|   Release the Kraken!
    )  __  (
   /,'))((`.\
  (( ((  )) ))
   `\ `)(' /'

Tell me a bit about your application:

[?] Description: ---
[?] Author: ---
[?] Template library? Dust
[?] CSS preprocessor library? SASS
[?] JavaScript library? None
   create .bowerrc
   create .editorconfig
   create .jshintignore
   create .jshintrc
   create .nodemonignore
   create .npmignore
   create Gruntfile.js
   create README.md
   create config\config.json
   create config\development.json
   create index.js
   create package.json
   create public\favicon.ico
   create public\js\.jshintignore
   create public\js\.jshintrc
   create public\js\app.js
   create tasks\clean.js
   create tasks\copyto.js
   create tasks\jshint.js
   create tasks\mochacli.js
   create locales\US\en\errors\404.properties
   create locales\US\en\errors\500.properties
   create locales\US\en\errors\503.properties
   create tasks\i18n.js
   create tasks\localizr.js
   create public\templates\errors\404.dust
   create public\templates\errors\500.dust
   create public\templates\errors\503.dust
   create public\templates\layouts\master.dust
   create tasks\dustjs.js
   create public\css\app.scss
   create tasks\sass.js
......and so on .......
  1. Then in a config/config.json file I change settings for a "router" from this default:
        "router": {
            "module": {
                "arguments": [{ "directory": "path:./controllers" }]
            }
        },

to this:

    "router": {
        "module": {
          "arguments": [{
            "routes": [
               { "path": "/",    "method": "GET", "handler": "require:./controllers/index" }
            ]
          }]
        }
    },
  1. And finally I start a server and try to make a request to http://localhost:8000/:
C:\sbox\helloworld>npm start

> helloworld@0.1.0 start C:\sbox\helloworld
> node index.js

[development] Listening on http://localhost:8000
body-parser deprecated urlencoded: explicitly specify "extended: true" for extended parsing node_modules\kraken-js\node_modules\meddleware\index.js:98:20

And a browser freezes. I shows that a page is loading and then an error page with ERR_EMPTY_RESPONSE appears. That's all.

Here are versions of Express and Kraken:

C:\sbox\helloworld>yo --version
1.1.2
C:\sbox\helloworld>express --version
4.2.0
aredridel commented 10 years ago

And what version of node?

aredridel commented 10 years ago

Output of npm ls might be useful too. (version of express that you have installed globally is not interesting, since nothing generated will depend on it. Version of the generator installed globally might be, though.)

wzup commented 10 years ago
C:\>node -v
v0.10.28

C:\sbox\helloworld>npm ls
helloworld@0.1.0 C:\sbox\helloworld
├─┬ adaro@0.1.5
│ └── core-util-is@1.0.1
├── dustjs-helpers@1.1.1
├── dustjs-linkedin@2.0.3
├─┬ engine-munger@0.2.0
│ ├─┬ concat-stream@1.4.6
│ │ ├── inherits@2.0.1
│ │ ├─┬ readable-stream@1.1.13-1
│ │ │ ├── core-util-is@1.0.1
│ │ │ ├── isarray@0.0.1
│ │ │ └── string_decoder@0.10.25-1
│ │ └── typedarray@0.0.6
│ ├── file-resolver@0.0.1
│ ├── graceful-fs@2.0.3
│ └─┬ karka@0.0.1
│   ├─┬ jshint@2.4.4
│   │ ├─┬ cli@0.4.5
│   │ │ └─┬ glob@4.0.2
│   │ │   ├── inherits@2.0.1
│   │ │   └── once@1.3.0
│   │ ├── console-browserify@0.1.6
│   │ ├── exit@0.1.2
│   │ ├─┬ htmlparser2@3.3.0
│   │ │ ├── domelementtype@1.1.1
│   │ │ ├── domhandler@2.1.0
│   │ │ ├── domutils@1.1.6
│   │ │ └─┬ readable-stream@1.0.27-1
│   │ │   ├── core-util-is@1.0.1
│   │ │   ├── inherits@2.0.1
│   │ │   ├── isarray@0.0.1
│   │ │   └── string_decoder@0.10.25-1
│   │ ├─┬ minimatch@0.3.0
│   │ │ ├── lru-cache@2.5.0
│   │ │ └── sigmund@1.0.0
│   │ ├── shelljs@0.1.4
│   │ └── underscore@1.4.4
│   ├── shortstop@0.0.1
│   └── shortstop-handlers@0.1.0
├─┬ express@4.4.5
│ ├─┬ accepts@1.0.6
│ │ ├── mime-types@1.0.1
│ │ └── negotiator@0.4.7
│ ├── buffer-crc32@0.2.3
│ ├── cookie@0.1.2
│ ├── cookie-signature@1.0.4
│ ├─┬ debug@1.0.2
│ │ └── ms@0.6.2
│ ├── escape-html@1.0.1
│ ├── fresh@0.2.2
│ ├── merge-descriptors@0.0.2
│ ├── methods@1.0.1
│ ├── parseurl@1.0.1
│ ├── path-to-regexp@0.1.2
│ ├─┬ proxy-addr@1.0.1
│ │ └── ipaddr.js@0.1.2
│ ├── qs@0.6.6
│ ├── range-parser@1.0.0
│ ├─┬ send@0.4.3
│ │ ├─┬ finished@1.2.2
│ │ │ └── ee-first@1.0.3
│ │ └── mime@1.2.11
│ ├── serve-static@1.2.3
│ ├─┬ type-is@1.2.1
│ │ └── mime-types@1.0.0
│ ├── utils-merge@1.0.0
│ └── vary@0.1.0
├─┬ grunt@0.4.1
│ ├── async@0.1.22
│ ├── coffee-script@1.3.3
│ ├── colors@0.6.2
│ ├── dateformat@1.0.2-1.2.3
│ ├── eventemitter2@0.4.14
│ ├─┬ findup-sync@0.1.3
│ │ ├─┬ glob@3.2.11
│ │ │ ├── inherits@2.0.1
│ │ │ └─┬ minimatch@0.3.0
│ │ │   ├── lru-cache@2.5.0
│ │ │   └── sigmund@1.0.0
│ │ └── lodash@2.4.1
│ ├─┬ glob@3.1.21
│ │ ├── graceful-fs@1.2.3
│ │ └── inherits@1.0.0
│ ├── hooker@0.2.3
│ ├── iconv-lite@0.2.11
│ ├─┬ js-yaml@2.0.5
│ │ ├─┬ argparse@0.1.15
│ │ │ ├── underscore@1.4.4
│ │ │ └── underscore.string@2.3.3
│ │ └── esprima@1.0.4
│ ├── lodash@0.9.2
│ ├─┬ minimatch@0.2.14
│ │ ├── lru-cache@2.5.0
│ │ └── sigmund@1.0.0
│ ├─┬ nopt@1.0.10
│ │ └── abbrev@1.0.5
│ ├─┬ rimraf@2.0.3
│ │ └── graceful-fs@1.1.14
│ ├── underscore.string@2.2.1
│ └── which@1.0.5
├─┬ grunt-config-dir@0.3.2
│ └─┬ fs-walk@0.0.1
│   └── async@0.9.0
├─┬ grunt-contrib-clean@0.5.0
│ └── rimraf@2.2.8
├─┬ grunt-contrib-jshint@0.10.0
│ ├── hooker@0.2.3
│ └─┬ jshint@2.5.1
│   ├─┬ cli@0.6.3
│   │ └─┬ glob@3.2.11
│   │   └── inherits@2.0.1
│   ├─┬ console-browserify@1.1.0
│   │ └── date-now@0.1.4
│   ├── exit@0.1.2
│   ├─┬ htmlparser2@3.7.2
│   │ ├── domelementtype@1.1.1
│   │ ├── domhandler@2.2.0
│   │ ├── domutils@1.5.0
│   │ ├── entities@1.0.0
│   │ └─┬ readable-stream@1.1.13-1
│   │   ├── core-util-is@1.0.1
│   │   ├── inherits@2.0.1
│   │   ├── isarray@0.0.1
│   │   └── string_decoder@0.10.25-1
│   ├─┬ minimatch@0.3.0
│   │ ├── lru-cache@2.5.0
│   │ └── sigmund@1.0.0
│   ├── shelljs@0.3.0
│   ├── strip-json-comments@0.1.3
│   └── underscore@1.6.0
├─┬ grunt-copy-to@0.0.10
│ └── lodash@2.4.1
├── grunt-dustjs@1.2.0
├─┬ grunt-localizr@0.1.0
│ ├─┬ concat-stream@1.4.6
│ │ ├── inherits@2.0.1
│ │ ├─┬ readable-stream@1.1.13-1
│ │ │ ├── core-util-is@1.0.1
│ │ │ ├── isarray@0.0.1
│ │ │ └── string_decoder@0.10.25-1
│ │ └── typedarray@0.0.6
│ ├── graceful-fs@2.0.3
│ ├── mkdirp@0.3.5
│ └── q@1.0.1
├─┬ grunt-mocha-cli@1.5.0
│ └─┬ mocha@1.16.2
│   ├── commander@2.0.0
│   ├─┬ debug@1.0.2
│   │ └── ms@0.6.2
│   ├── diff@1.0.7
│   ├─┬ glob@3.2.3
│   │ ├── graceful-fs@2.0.3
│   │ ├── inherits@2.0.1
│   │ └─┬ minimatch@0.2.14
│   │   ├── lru-cache@2.5.0
│   │   └── sigmund@1.0.0
│   ├── growl@1.7.0
│   ├─┬ jade@0.26.3
│   │ ├── commander@0.6.1
│   │ └── mkdirp@0.3.0
│   └── mkdirp@0.3.5
├─┬ grunt-sass@0.12.1
│ ├─┬ chalk@0.4.0
│ │ ├── ansi-styles@1.0.0
│ │ ├── has-color@0.1.7
│ │ └── strip-ansi@0.1.1
│ └── each-async@0.1.3
├─┬ kraken-devtools@1.0.0
│ ├── async@0.2.10
│ ├─┬ concat-stream@1.4.6
│ │ ├── inherits@2.0.1
│ │ ├─┬ readable-stream@1.1.13-1
│ │ │ ├── core-util-is@1.0.1
│ │ │ ├── isarray@0.0.1
│ │ │ └── string_decoder@0.10.25-1
│ │ └── typedarray@0.0.6
│ ├─┬ minimatch@0.2.14
│ │ ├── lru-cache@2.5.0
│ │ └── sigmund@1.0.0
│ ├── mkdirp@0.3.5
│ └── rimraf@2.2.8
├─┬ kraken-js@1.0.1
│ ├── bluebird@1.2.4
│ ├─┬ body-parser@1.4.3
│ │ ├── bytes@1.0.0
│ │ ├── depd@0.3.0
│ │ ├── iconv-lite@0.4.3
│ │ ├── media-typer@0.2.0
│ │ ├── qs@0.6.6
│ │ ├── raw-body@1.2.2
│ │ └─┬ type-is@1.3.1
│ │   └── mime-types@1.0.0
│ ├─┬ caller@0.0.1
│ │ └─┬ tape@2.3.3
│ │   ├── deep-equal@0.1.2
│ │   ├── defined@0.0.0
│ │   ├── inherits@2.0.1
│ │   ├── jsonify@0.0.0
│ │   ├── resumer@0.0.0
│ │   └── through@2.3.4
│ ├─┬ compression@1.0.8
│ │ ├─┬ accepts@1.0.6
│ │ │ ├── mime-types@1.0.1
│ │ │ └── negotiator@0.4.7
│ │ ├── bytes@1.0.0
│ │ ├── compressible@1.1.0
│ │ ├── on-headers@0.0.0
│ │ └── vary@0.1.0
│ ├─┬ confit@1.2.0
│ │ ├── async@0.7.0
│ │ ├── debuglog@1.0.1
│ │ ├── minimist@0.0.10
│ │ └── shortstop-handlers@0.1.0
│ ├─┬ cookie-parser@1.3.2
│ │ ├── cookie@0.1.2
│ │ └── cookie-signature@1.0.4
│ ├── core-util-is@1.0.1
│ ├── debuglog@0.0.4
│ ├── endgame@0.0.3
│ ├─┬ express-enrouten@1.1.1
│ │ ├── debuglog@1.0.1
│ │ └─┬ reverend@0.2.0
│ │   └── path-to-regexp@0.1.2
│ ├─┬ express-session@1.5.2
│ │ ├── buffer-crc32@0.2.3
│ │ ├── cookie@0.1.2
│ │ ├── cookie-signature@1.0.4
│ │ ├─┬ debug@1.0.2
│ │ │ └── ms@0.6.2
│ │ ├── depd@0.3.0
│ │ ├── on-headers@0.0.0
│ │ ├─┬ uid-safe@1.0.1
│ │ │ ├── base64-url@1.0.0
│ │ │ └── mz@1.0.0
│ │ └── utils-merge@1.0.0
│ ├── formidable@1.0.15
│ ├── lusca@1.0.1
│ ├── meddleware@1.0.0
│ ├─┬ morgan@1.1.1
│ │ └── bytes@1.0.0
│ ├─┬ serve-static@1.2.3
│ │ ├── escape-html@1.0.1
│ │ ├── parseurl@1.0.1
│ │ └─┬ send@0.4.3
│ │   ├─┬ debug@1.0.2
│ │   │ └── ms@0.6.2
│ │   ├─┬ finished@1.2.2
│ │   │ └── ee-first@1.0.3
│ │   ├── fresh@0.2.2
│ │   ├── mime@1.2.11
│ │   └── range-parser@1.0.0
│ ├─┬ shortstop@1.0.1
│ │ └── async@0.2.10
│ ├─┬ shortstop-handlers@1.0.0
│ │ └─┬ glob@3.2.11
│ │   ├── inherits@2.0.1
│ │   └─┬ minimatch@0.3.0
│ │     ├── lru-cache@2.5.0
│ │     └── sigmund@1.0.0
│ ├─┬ shush@0.0.1
│ │ └── strip-json-comments@0.1.3
│ └── static-favicon@1.0.2
├─┬ localizr@0.1.0
│ ├─┬ findatag@0.0.9
│ │ ├── async@0.2.10
│ │ └── readable-stream@1.0.15
│ ├── minimist@0.0.7
│ ├── mkdirp@0.3.5
│ └─┬ spud@0.0.3
│   └── string.fromcodepoint@0.1.0
├─┬ mocha@1.20.1
│ ├── commander@2.0.0
│ ├─┬ debug@1.0.2
│ │ └── ms@0.6.2
│ ├── diff@1.0.7
│ ├─┬ glob@3.2.3
│ │ ├── graceful-fs@2.0.3
│ │ ├── inherits@2.0.1
│ │ └─┬ minimatch@0.2.14
│ │   ├── lru-cache@2.5.0
│ │   └── sigmund@1.0.0
│ ├── growl@1.7.0
│ ├─┬ jade@0.26.3
│ │ ├── commander@0.6.1
│ │ └── mkdirp@0.3.0
│ └── mkdirp@0.3.5
├─┬ node-sass@0.8.4
│ ├─┬ chalk@0.3.0
│ │ ├── ansi-styles@0.2.0
│ │ └── has-color@0.1.7
│ ├── mkdirp@0.3.5
│ ├─┬ mocha@1.13.0
│ │ ├── commander@0.6.1
│ │ ├─┬ debug@1.0.2
│ │ │ └── ms@0.6.2
│ │ ├── diff@1.0.7
│ │ ├─┬ glob@3.2.3
│ │ │ ├── graceful-fs@2.0.3
│ │ │ ├── inherits@2.0.1
│ │ │ └─┬ minimatch@0.2.14
│ │ │   ├── lru-cache@2.5.0
│ │ │   └── sigmund@1.0.0
│ │ ├── growl@1.7.0
│ │ └─┬ jade@0.26.3
│ │   └── mkdirp@0.3.0
│ ├── nan@0.6.0
│ ├── node-watch@0.3.4
│ └─┬ optimist@0.6.1
│   ├── minimist@0.0.10
│   └── wordwrap@0.0.2
└─┬ supertest@0.9.2
  ├── methods@0.1.0
  └─┬ superagent@0.17.0
    ├── cookiejar@1.3.0
    ├── debug@0.7.4
    ├── emitter-component@1.0.0
    ├── extend@1.2.1
    ├── formidable@1.0.14
    ├── methods@0.0.1
    ├── mime@1.2.5
    ├── qs@0.6.5
    └── reduce-component@1.0.1
totherik commented 10 years ago

I can confirm that the configuration you're describing does indeed work with vanilla express-enrouten. An example project is in the routes-example, which I created to isolate and verify kraken-js and express-enrouten. Feel free to clone, npm install and start the app.

If the generator is creating a configuration that prevents this type of project/routing from working, this issue should be moved to that repo.

Additionally, it's not clear what you changed after my initial reply. In your recap of what you did you mentioned starting mongo, which is unnecessary for a freshly generated kraken app. Did you completely remove your original index.js file and start fresh?

totherik commented 10 years ago

Also, I apologize, I missed one point. Please try that app on your Windows machine. I was only able to test on OS X.

wzup commented 10 years ago

I've just tested routes-example app on my Windows 7 64bit and it works just fine. No issues. Both routes (/ and /foo) open its pages (ok and foo strings are shown respectively).

Additionally, it's not clear what you changed after my initial reply

In a freshly generated krakenjs app I didn't change anything except "router" key in a config.js file. I didn't touch index.js at all at all. Just freshly generated app.

So, it seems that there is some conflict with the generator. I'll try to find out what it is )

Thank you all.

jasisk commented 10 years ago

Hey @wzup, I've opened an issue on your behalf: krakenjs/generator-kraken#109. Let's track progress over there.

wzup commented 10 years ago

Where may I read more about configuration syntax and rules? I mean these. How do you know how to write it:

config.set('middleware:router:module:arguments', [{
{ path: '/',    method: 'GET', handler: require('./controllers/index') },
jasisk commented 10 years ago

Configuration is handled by confit. That particular config corresponds to this line which you can find in /config/config.json. The short answer is that each colon in the config you're trying to get is a nested object, so middleware:router:module:arguments corresponds to:

{
  "middleware": {
    "router": {
      "module": {
        "arguments": "THIS RIGHT HERE"
      }
    }
  }
}

Written out, that line basically says to change the arguments passed to the router middleware to [{ path: '/', method: 'GET', handler: require('./controllers/index')}] instead of the default (linked to above).

You can accomplish the same thing by just changing the config.json itself.