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

adding flexibility for attaching alexa-app to express #177

Merged
merged 17 commits into from
Feb 16, 2017

Conversation

bgjehu
Copy link
Contributor

@bgjehu bgjehu commented Feb 13, 2017

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()

bgjehu and others added 8 commits February 13, 2017 10:52
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).
Copy link
Collaborator

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?

@dblock
Copy link
Collaborator

dblock commented Feb 14, 2017

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.

@tejashah88 tejashah88 mentioned this pull request Feb 14, 2017
@tejashah88
Copy link
Member

tejashah88 commented Feb 14, 2017

Looks great so far, except for that endpoint does not have any normalization (i.e. ////test is valid).

@bgjehu
Copy link
Contributor Author

bgjehu commented Feb 14, 2017

@dblock I will work on better explanation on CHANGELOG.md, work on testing with alexa-app-server and updating UPGRADING.md
@tejashah88 I will add the usage of normalization

index.js Outdated

options.expressApp.use(endpoint, router);
// In ExpressJS, user specifies their paths without the '/' prefix
var endpoint = options.endpoint;
Copy link
Member

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
@bgjehu
Copy link
Contributor Author

bgjehu commented Feb 15, 2017

@dblock @tejashah88

  • clarified changes in CHANGELOG.md
  • 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

@dblock
Copy link
Collaborator

dblock commented Feb 15, 2017

How do all our alexa-app-server tests pass when we're no longer attaching the router to the express instance? :)

@bgjehu
Copy link
Contributor Author

bgjehu commented Feb 15, 2017

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.");
Copy link
Member

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");
Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bgjehu Sure. Let's see what @dblock has to say.

Copy link
Collaborator

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?

Copy link
Contributor Author

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).
Copy link
Collaborator

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"?

Copy link
Contributor Author

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!

Copy link
Collaborator

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

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.

Copy link
Contributor Author

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dblock will do!

@@ -0,0 +1,83 @@
/*jshint expr: true*/
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dblock yes sir

@dblock
Copy link
Collaborator

dblock commented Feb 15, 2017

I made some comments. Sorry to be a pest, I want to make sure we don't break a bunch of users.

@bgjehu
Copy link
Contributor Author

bgjehu commented Feb 16, 2017

@dblock @tejashah88
Backward compatible tested with alexa-app-server
image

@dblock
Copy link
Collaborator

dblock commented Feb 16, 2017

I'm going to merge this, nice work on a spec, too!

I'd appreciate a follow-up pull request that:

  • Deletes unused functions in utils.
  • Slightly tweaks UPGRADING to say that the behavior with both is deprecated rather than removed.

@dblock dblock merged commit b30997f into alexa-js:master Feb 16, 2017
@dblock
Copy link
Collaborator

dblock commented Feb 16, 2017

@tejashah88 Interested in cutting a minor release with this change?

@bgjehu
Copy link
Contributor Author

bgjehu commented Feb 16, 2017

@dblock there is unused functional in utils? I saw the coverage for utils.js is 100%
will tweaks UPGRADING

@dblock
Copy link
Collaborator

dblock commented Feb 16, 2017

coverage means there're tests, but half the functions in utils aren't actually used, eg. isValidDirectory, other than by code in those tests

@bgjehu
Copy link
Contributor Author

bgjehu commented Feb 17, 2017

right right right, silly me. I will double check and remove the unused

@tejashah88
Copy link
Member

tejashah88 commented Feb 17, 2017

@dblock We can do a release, however the CHANGELOG states that version 3.1.2 should be released today (2/16/2017).

@tejashah88
Copy link
Member

We should either go to 3.1.1 or 4.0.0, or wait until all relevant PRs are merged before deciding.

@dblock
Copy link
Collaborator

dblock commented Feb 17, 2017

The CHANGELOG is wrong, it shouldn't have been updated. The current release is still 3.1.0.

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

Successfully merging this pull request may close these issues.

3 participants