Skip to content
This repository has been archived by the owner on Jan 25, 2020. It is now read-only.

API usage is little confused #9

Closed
outsideris opened this issue Dec 16, 2013 · 7 comments
Closed

API usage is little confused #9

outsideris opened this issue Dec 16, 2013 · 7 comments

Comments

@outsideris
Copy link

in README

var express = require('express'),
    enrouten = require('express-enrouten');

var app = express();
express.use(enrouten({ ... });

but in index.js, another express instance is created. so there are two express instances.

Therfore when I use express-enrouten without kraken, I configure some settings in express app, but the settings doesn't apply in controllers.
I guess the reason it's different instance.

@totherik
Copy link
Member

Unfortunately, for now the new API is not compatible with kraken-js. Kraken does some funny things internally that are not inherited by mounted express applications. I have a separate bit of work going on in parallel to clean up kraken-js to fix this compatibility issue, but for now the old API will continue to function as expected.

Additionally, kraken-js uses the old API internally, so it should be necessary to use this module directly if you're building a kraken-js app.

@outsideris
Copy link
Author

As I said, I use express-enrouten without kraken.(I try to use kraken but....) so I use express directly.

//var app = express();
var app = enrouten({directory: 'controllers'});

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

as you can see above, I made express instance via express-enrouten not directly.
Is it intended?

@lmarkus
Copy link
Contributor

lmarkus commented Dec 17, 2013

@outsideris
Yes, this is intended.
I think we just have a slight typo in our docs.

var app = express();
express.use(enrouten({ ... });

The second line should be app.use(enrouten({ ... });

The reason for this is that express allow for mounting different instances to service different parts of an application.

When we do:

var primaryApp = express();
var enroutedApp = enrouten({ config });

primaryApp.use(enroutedApp);

We are telling the primaryApp to use enroutedApp to service all requests sent to / (Since we didn't specify a route, it defaults to root).

Does this help to clarify things a bit?

@totherik
Copy link
Member

Sorry about the @outsideris, I misread your original issue. You are correct, the new API has a bug in which the views property is not inherited by the mounted app. As you can see express resets a few properties, including views when a new app is created, inheriting the rest of the settings just fine. I'll have a PR to fix this issue shortly.

@totherik
Copy link
Member

Also, the README has been updated, so thanks for pointing out that issue. The API should be:

var express = require('express'),
    enrouten = require('express-enrouten');

var app = express();
app.use(enrouten({ ... });

@lmarkus
Copy link
Contributor

lmarkus commented Dec 17, 2013

Fixed via #10 and #11

@lmarkus lmarkus closed this as completed Dec 17, 2013
@outsideris
Copy link
Author

Appreciate!!! 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants