Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.

[WIP] refactor(hapi): Upgrade to hapi 17#334

Open
deeptibaghel wants to merge 14 commits into
mozilla:masterfrom
deeptibaghel:hapi17
Open

[WIP] refactor(hapi): Upgrade to hapi 17#334
deeptibaghel wants to merge 14 commits into
mozilla:masterfrom
deeptibaghel:hapi17

Conversation

@deeptibaghel
Copy link
Copy Markdown
Contributor

@deeptibaghel deeptibaghel commented Jul 31, 2018

Fixes #333

@ghost ghost assigned deeptibaghel Jul 31, 2018
@ghost ghost added the waffle:active label Jul 31, 2018
Copy link
Copy Markdown
Contributor

@vladikoff vladikoff left a comment

Choose a reason for hiding this comment

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

I'll check 'static' in a bit

Comment thread lib/profileCache.js Outdated
@@ -91,7 +91,7 @@ module.exports = function profileCache(server, options, next) {
scope: scope
}}};
return P.fromCallback(cb => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

there is a cb here, should that be removed and function below needs to 'return'?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we should check if cache.drop still uses callbacks or not

Comment thread lib/routes/avatar/get.js Outdated
handler: function avatar(req, reply) {
handler: async function avatar(req) {
var uid = req.auth.credentials.user;
db.getSelectedAvatar(uid)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

does this need a 'return'?

Comment thread lib/routes/avatar/delete.js Outdated
@@ -63,8 +63,7 @@ module.exports = {
.then(() => {
notifyProfileUpdated(uid); // Don't wait on promise
return EMPTY;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

need to check 'EMPTY' vs the {} above

Comment thread lib/routes/avatar/upload.js Outdated
handler: function upload(req, reply) {
handler: async function upload(req, h) {
const uid = req.auth.credentials.user;
req.server.methods.profileCache.drop(uid, () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

does this need to return?, also no more callbacks?

Comment thread lib/routes/email.js Outdated
@@ -26,20 +26,20 @@ module.exports = {
credentials: req.auth.credentials
}, res => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

no callbacks in inject?

Comment thread lib/server/web.js
cors: true,
security: {
hsts: {
maxAge: 15552000,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we had a different fix for this to make sure these headers are set ?

Comment thread lib/routes/heartbeat.js Outdated
handler: function heartbeat(req, reply) {
db.ping().done(reply, reply);
handler: async function heartbeat() {
db.ping().then(() => {});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

return?

Comment thread lib/server/web.js
server.route(routes);

server.ext('onPreAuth', function (request, reply) {
server.ext('onPreAuth', function (request, h) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

are these stilp callbacks? need to check..

Comment thread lib/server/worker.js Outdated
config: {
handler: function upload(req, reply) {
reply({});
handler: async function upload(req) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

function name 'upload' is wrong here, lets fix

Comment thread lib/routes/display_name/post.js Outdated
const uid = req.auth.credentials.user;
req.server.methods.profileCache.drop(uid, () => {
const payload = req.payload;
db.setDisplayName(uid, payload.displayName)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

return here as well?

Comment thread bin/worker.js Outdated
async function start(){
const server = await require('../lib/server/worker').create();

server.start(function() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think there is a callback anymore on .start, You need to do await server.start()
and surround it with the a try and catch to throw an error if it fails to .start

Comment thread bin/worker.js Outdated
server.start(function() {
logger.info('listening', server.info.uri);
});
async function start(){
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

style: start() { (space before {

Comment thread lib/profileCache.js
cache: {
expiresIn: options.expiresIn,
generateTimeout: options.generateTimeout
generateTimeout: options.generateTimeout || 100
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we change that in the tests instead and should not do this here

Copy link
Copy Markdown
Contributor Author

@deeptibaghel deeptibaghel Aug 2, 2018

Choose a reason for hiding this comment

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

it was throwing error here generateTimeout is required so i added it temporarily

Comment thread lib/routing.js
method: 'POST',
path: v('/display_name'),
config: require('./routes/display_name/post')
options: require('./routes/display_name/post')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice 👍

Comment thread lib/server/_static.js
host: config.server.host,
port: config.server.port + 1,
debug: { request: ['error'] }
debug: false
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hm not sure about this change, I wonder what { request: ['error'] } used to do

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it was originally false only

Comment thread lib/server/web.js Outdated
port: config.server.port,
cache: cache,
debug: false,
debug: { request: ['error'] },
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ahh

Comment thread lib/server/web.js Outdated
// server method for caching profile
try {
await server.register({
name: 'fxa-profile-server',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe we can call this just profileCache

Comment thread lib/server/web.js Outdated
});

server.ext('onPreResponse', function(request, next) {
server.ext('onPreResponse', function(request, h) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we need the h here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we have h.continue below

@deeptibaghel
Copy link
Copy Markdown
Contributor Author

@vladikoff still i am missing something :(

Comment thread bin/_static.js Outdated

async function create() {
const server = await require('../lib/server/_static').create();
server.start().then(() => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should use await server.start(); here , move the log out of then. Just like below: https://github.com/mozilla/fxa-profile-server/pull/334/files#diff-8d44631bfd02d64ee75348ab92f466c0R27

Comment thread lib/routes/avatar/delete.js Outdated
return workers.delete(avatar.id);
}
})
req.server.methods.profileCache.drop(uid)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks like this will fail because this doesn't return

Comment thread lib/routes/avatar/upload.js Outdated
// precaution to avoid the default id from being overwritten
assert(id !== DEFAULT_AVATAR_ID);
const url = avatarShared.fxaUrl(id);
workers.upload(id, req.payload, req.headers)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this also needs to return otherwise response will be lost

Comment thread lib/routes/display_name/post.js Outdated
})
.done(reply, reply);
});
req.server.methods.profileCache.drop(uid)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this will fail, no return

Comment thread lib/routes/display_name/post.js Outdated
req.server.methods.profileCache.drop(uid)
.then(() => {
const payload = req.payload;
db.setDisplayName(uid, payload.displayName)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

needs return here too

Comment thread lib/server/_static.js Outdated
switch (request.params.type) {
case '':
reply.file(DEFAULT_AVATAR);
h.file(DEFAULT_AVATAR);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we make h.file a return h.file ?

Comment thread lib/profileCache.js Outdated
return next(null, result, ttl);
})
.catch(next);
.then(result => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@vladikoff , I have fixed the server stop function but it still didn't work. This method seems to be failing.

Comment thread lib/profileCache.js Outdated
server.methods.profileCache.get.cache.drop(req, cb);
});
}).asCallback(next);
await server.methods.profileCache.get.cache.drop(req);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@vladikoff , this method is not right yet, how do we change it correctly ?

Comment thread lib/profileCache.js Outdated
@@ -90,7 +90,10 @@ module.exports = function profileCache(server, options) {
scope: scope
}}};
return await server.methods.profileCache.get.cache.drop(req);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@vladikoff this line is throwing a 500 error, am I missing something ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@deeptibaghel do you get this when running the tests?

Comment thread .eslintrc Outdated
semi: [2, "always"]

parserOptions:
ecmaVersion: 2017
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

let's make this 2018 here

Comment thread lib/config.js Outdated
},
serverCache: {
redis: {
// name: 'redisCache',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what happens here? is this not named anymore? do we delete it?

Comment thread lib/routes/avatar/upload.js Outdated
const url = avatarShared.fxaUrl(id);
await workers.upload(id, req.payload, req.headers);
await db.addAvatar(id, uid, url, FXA_PROVIDER);
await notifyProfileUpdated(uid); // Don't wait on promise
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

per // Don't wait on promise , we don't want an await here

Comment thread lib/routes/display_name/post.js Outdated
})
.done(reply, reply);
});
return req.server.methods.profileCache.drop(uid)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if we are changing the upload.js above to use async await, then we should do it here as well. or we can use the .then structure above. Pick the one you like.

Comment thread lib/routes/email.js Outdated
// we should always get an email field back.
if (! res.result.email) {
logger.error('request.auth_server.fail', res.result);
return new AppError({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we throw here?

Comment thread lib/routes/root.js Outdated
handler: function index(req, reply) {
function sendReply() {
reply({
// response: {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what happened here?

Comment thread lib/profileCache.js Outdated
@@ -90,7 +90,10 @@ module.exports = function profileCache(server, options) {
scope: scope
}}};
return await server.methods.profileCache.get.cache.drop(req);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@deeptibaghel do you get this when running the tests?

Comment thread lib/profileCache.js
scope: scope
}}};
return await server.methods.profileCache.get.cache.drop(req);
return server.methods.profileCache.get.cache.drop(req);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@vladikoff the test to upload avatar fails at this point

@shane-tomlinson
Copy link
Copy Markdown

I'm leaving this PR open because we still want this work! We will need to migrate this to the new mono-repo: github.com/mozilla/fxa

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants