-
Notifications
You must be signed in to change notification settings - Fork 212
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
adding flexibility for attaching alexa-app to express #177
adding flexibility for attaching alexa-app to express #177
Conversation
increase flexibility for attaching alexa to either an express app or router
flexibility for attaching alexa to express
…ng-to-express # Conflicts: # CHANGELOG.md # package.json
Merge pull request #1 from bgjehu/flexibility-attaching-to-express
CHANGELOG.md
Outdated
@@ -1,6 +1,7 @@ | |||
## Changelog | |||
|
|||
### 4.0.0 (Next) | |||
* [#176](https://github.com/alexa-js/alexa-app/pull/176): Added flexibility to attach alexa-app to express app or router - [@bgjehu](https://github.com/bgjehu). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a better explanation that "flexibility", maybe Express router is now optional?
This looks right to me, but I have this feeling that we're missing something, cc: @tejashah88. @bgjehu Try this against alexa-app-server please, any failing tests? The PR needs to be rebased, and see my minor comment on CHANGELOG above. Please add a paragraph to UPGRADING wrt what one should do if they specified both express app and router before. |
Looks great so far, except for that |
@dblock I will work on better explanation on CHANGELOG.md, work on testing with alexa-app-server and updating UPGRADING.md |
index.js
Outdated
|
||
options.expressApp.use(endpoint, router); | ||
// In ExpressJS, user specifies their paths without the '/' prefix | ||
var endpoint = options.endpoint; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bgjehu This should be var endpoint = utils.normalizeApiPath(options.endpoint);
* added normalization of param 'endpoint' for alexa.express() with util fn * added upgrading guide for ExpressJS support in UPGRADING.md
not related to the commit, I testedthe new logic with alexa-app-server, swap the alexa-app node_module to my fork for all the examples (including the invalid ones), all test passed. However, not changing anything in alexa-app-server for its package.json is point to alexa-app@3.0.0 instead of 4.0.0. I would apply the associated changes to alexa-app-server once it starts pointing to alexa-app@4.0.0 |
How do all our alexa-app-server tests pass when we're no longer attaching the router to the express instance? :) |
I had made related changes in alexa-app-server/index.js as well before I ran the test. They didn't just pass without changes for the usage of alexa.express() would be different. |
index.js
Outdated
throw new Error("You must specify an express router to attach."); | ||
if (options.expressApp && options.router) { | ||
console.warn("Since alexa-app@4.0.0, you are no longer required to pass both 'expressApp' and 'router'."); | ||
console.warn("When both passed, 'alexa-app' would be attached to 'expressApp' instance."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, the warning message I would have done is something along the lines of "'expressApp' and 'router' are both specified, using 'expressApp'...
". Generally, I want to give the user just the warning itself, and if they want to know more about it, they could look up UPGRADING.md for more information.
index.js
Outdated
@@ -566,8 +566,7 @@ alexa.app = function(name) { | |||
} | |||
|
|||
if (options.expressApp && options.router) { | |||
console.warn("Since alexa-app@4.0.0, you are no longer required to pass both 'expressApp' and 'router'."); | |||
console.warn("When both passed, 'alexa-app' would be attached to 'expressApp' instance."); | |||
console.warn("Both 'expressApp' and 'router' are specified, attaching to 'expressApp' only.\nMore details on https://github.com/alexa-js/alexa-app/blob/master/UPGRADING.md"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tejashah88 would this be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should either be an exception or be backward compatible and produce a warning that this behavior is deprecated.
If we ignore router
, the user is not getting the behavior from the previous release and we just tell them "sorry, it's not going to work, but we are going to pretend like it does" :)
I actually would prefer a backward compatible version here with a warning, because that allows a lot more flexibility in combining versions of alexa-app-server and alexa-app.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dblock make sense. Making it backward compatible tonight.
CHANGELOG.md
Outdated
@@ -1,6 +1,7 @@ | |||
## Changelog | |||
|
|||
### 4.0.0 (Next) | |||
* [#176](https://github.com/alexa-js/alexa-app/pull/176): Made params `expressApp` and `router` optional for `alexa.express()` - [@bgjehu](https://github.com/bgjehu). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not what this change does, one of the two is required. So maybe "Express integration now requires either expressApp
or router
, but not both"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dblock thanks for offering the words. I am not good with words and describing things! Will do the changes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're doing great, no stress!
README.md
Outdated
* `checkCert` when true, applies Alexa certificate checking _(default: true)_ | ||
* `debug` when true, sets up the route to handle GET requests _(default: false)_ | ||
* `preRequest` function to execute before every POST | ||
* `postRequest` function to execute after every POST | ||
|
||
Either `expressApp` or `router` has to be specified so that alexa-app could be attached to. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has to be specified so that alexa-app could be attached to => is required
. I think it's clear what that does already from above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dblock will do
UPGRADING.md
Outdated
@@ -39,6 +39,48 @@ app.intent("tellme", (request, response) => { | |||
}); | |||
``` | |||
|
|||
#### Changes to ExpressJS Support | |||
|
|||
After changes, `alexa.express()` no longer requires both `expressApp` and `router` to be passes in. Instead, just pass in either an express app or router. And alexa-app would be bind to it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not the whole change. Also it's unclear what alexa
is, it should be app
, and "to be passed in" is redundant. And the next sentence says the same thing. Maybe:
Express.js integration via `app.express()` now requires one of `expresApp` or `router`. When using a router, it will no longer be automatically mounted inside the express app and you may need to implement that outside of this call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dblock will do!
test/test_utils.js
Outdated
@@ -0,0 +1,83 @@ | |||
/*jshint expr: true*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets delete unused functions here? The only one utilized is normalizeApiPath
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dblock yes sir
I made some comments. Sorry to be a pest, I want to make sure we don't break a bunch of users. |
@dblock @tejashah88 |
I'm going to merge this, nice work on a spec, too! I'd appreciate a follow-up pull request that:
|
@tejashah88 Interested in cutting a minor release with this change? |
@dblock there is unused functional in utils? I saw the coverage for utils.js is 100% |
coverage means there're tests, but half the functions in utils aren't actually used, eg. |
right right right, silly me. I will double check and remove the unused |
We should either go to |
The CHANGELOG is wrong, it shouldn't have been updated. The current release is still 3.1.0. |
change alexa.express()
so that it takes either an express app or router and attach alexa-app to it under given endpoint.
leave the logic of binding router to app out of the scope of alexa-app/alexa.express()