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

Basic implementation #1

Merged
merged 20 commits into from
Oct 26, 2018
Merged

Basic implementation #1

merged 20 commits into from
Oct 26, 2018

Conversation

quaelin
Copy link
Member

@quaelin quaelin commented Oct 22, 2018

@quaelin quaelin changed the title [WIP] Basic implementation Basic implementation Oct 24, 2018
@quaelin
Copy link
Member Author

quaelin commented Oct 24, 2018

Reviewers, please note that I'd like to eventually open source this repo.

@quaelin quaelin self-assigned this Oct 24, 2018
package.json Outdated
"aws-sdk": "^2.338.0",
"fnv-plus": "^1.2.12",
"jsbn": "^1.1.0",
"lodash": "^4.17.11"

Choose a reason for hiding this comment

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

Maybe worth importing the single-function lodash modules that are used? If I'm not mistaken a lighter dependency load could improve lambda cold start time

api/store.js Outdated
const {
bucket,
debug,
domain_whitelist: domainWhitelist,

Choose a reason for hiding this comment

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

With an eye to open-sourcing, you might consider domainSafeList instead

api/store.js Outdated
if (!_.find(domainWhitelist, suffixMatcher)) {
throw new HttpError(
400,
`Not an allowed domain for shortening: ${host}, whitelist: ${domainWhitelist}`

Choose a reason for hiding this comment

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

It might be undesirable from a security standpoint to surface the entire list of allowable domains to external callers (which I think is what would happen, unless this message is removed from the output later on)

api/store.js Show resolved Hide resolved
api/store.js Outdated
.then(() => hash);
}

function sendResponse(statusCode, { message, path }, callback) {

Choose a reason for hiding this comment

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

My (strong) preference is not to pass callbacks out of scope and allow collaborator functions to invoke them - what do you think of turning this inside out so it just returns the object for the callback, then the main handler function would invoke it like callback(null, buildResponse(statusCode, { message, path })?

api/store.js Outdated

do {
const quotientAndRemainder = workingValue.divideAndRemainder(base);
const quotient = quotientAndRemainder[0];
Copy link

Choose a reason for hiding this comment

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

can use destructuring to simplify here

const [quotient, remainder] = workingValue.divideAndRemainder(base);

package.json Outdated
"engines": {
"node": "8.10.0"
},
"dependencies": {
"aws-sdk": "^2.338.0"
"aws-sdk": "^2.338.0",

Choose a reason for hiding this comment

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

We don't need to have this as a dependency because AWS Lambda includes this automatically. Including it here is redundant and greatly increases the size of the package that gets uploaded to AWS, which affects cold start time.

If we add it to devDependencies, we can still use it for developing and testing locally.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice! This change reduced the .zip file size from 6.24 MB to 148.2 KB, and it still works!

describe('When the `url` property', () => {
test(
'is not a valid URL, we get a 400 response',
() => expectStatusForUrl('not a url', 400)

Choose a reason for hiding this comment

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

Are we able to add expectations for the error messages as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

We were already testing for the existence of a message string in the response body. I've just added a line to additionally test that the message is non-empty... but tests for each individual message string seems like overkill.

@koozdra
Copy link

koozdra commented Oct 26, 2018

LGTM ✨

Copy link

@zimerick zimerick left a comment

Choose a reason for hiding this comment

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

Code looks great, couple questions & some in slack re deployment config.

storage and redirection.

The serverless scaffolding for this was largely lifted from
[@danielireson](https://github.com/danielireson)'s excellent

Choose a reason for hiding this comment

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

should "'s excellent" be here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Wanted to give credit where it's due. :)

api/store.js Show resolved Hide resolved
@ryanatwork
Copy link
Member

LGTM!

@quaelin quaelin merged commit 767e0b9 into master Oct 26, 2018
@quaelin quaelin deleted the chris/scaffolding branch October 26, 2018 16:59
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.

6 participants