[WIP] refactor(hapi): Upgrade to hapi 17#334
[WIP] refactor(hapi): Upgrade to hapi 17#334deeptibaghel wants to merge 14 commits intomozilla:masterfrom
Conversation
vladikoff
left a comment
There was a problem hiding this comment.
I'll check 'static' in a bit
lib/profileCache.js
Outdated
| @@ -91,7 +91,7 @@ module.exports = function profileCache(server, options, next) { | |||
| scope: scope | |||
| }}}; | |||
| return P.fromCallback(cb => { | |||
There was a problem hiding this comment.
there is a cb here, should that be removed and function below needs to 'return'?
There was a problem hiding this comment.
we should check if cache.drop still uses callbacks or not
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) |
There was a problem hiding this comment.
does this need a 'return'?
lib/routes/avatar/delete.js
Outdated
| @@ -63,8 +63,7 @@ module.exports = { | |||
| .then(() => { | |||
| notifyProfileUpdated(uid); // Don't wait on promise | |||
| return EMPTY; | |||
There was a problem hiding this comment.
need to check 'EMPTY' vs the {} above
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, () => { |
There was a problem hiding this comment.
does this need to return?, also no more callbacks?
lib/routes/email.js
Outdated
| @@ -26,20 +26,20 @@ module.exports = { | |||
| credentials: req.auth.credentials | |||
| }, res => { | |||
| cors: true, | ||
| security: { | ||
| hsts: { | ||
| maxAge: 15552000, |
There was a problem hiding this comment.
I think we had a different fix for this to make sure these headers are set ?
lib/routes/heartbeat.js
Outdated
| handler: function heartbeat(req, reply) { | ||
| db.ping().done(reply, reply); | ||
| handler: async function heartbeat() { | ||
| db.ping().then(() => {}); |
| server.route(routes); | ||
|
|
||
| server.ext('onPreAuth', function (request, reply) { | ||
| server.ext('onPreAuth', function (request, h) { |
There was a problem hiding this comment.
are these stilp callbacks? need to check..
lib/server/worker.js
Outdated
| config: { | ||
| handler: function upload(req, reply) { | ||
| reply({}); | ||
| handler: async function upload(req) { |
There was a problem hiding this comment.
function name 'upload' is wrong here, lets fix
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) |
bin/worker.js
Outdated
| async function start(){ | ||
| const server = await require('../lib/server/worker').create(); | ||
|
|
||
| server.start(function() { |
There was a problem hiding this comment.
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
bin/worker.js
Outdated
| server.start(function() { | ||
| logger.info('listening', server.info.uri); | ||
| }); | ||
| async function start(){ |
There was a problem hiding this comment.
style: start() { (space before {
| cache: { | ||
| expiresIn: options.expiresIn, | ||
| generateTimeout: options.generateTimeout | ||
| generateTimeout: options.generateTimeout || 100 |
There was a problem hiding this comment.
I think we change that in the tests instead and should not do this here
There was a problem hiding this comment.
it was throwing error here generateTimeout is required so i added it temporarily
| method: 'POST', | ||
| path: v('/display_name'), | ||
| config: require('./routes/display_name/post') | ||
| options: require('./routes/display_name/post') |
| host: config.server.host, | ||
| port: config.server.port + 1, | ||
| debug: { request: ['error'] } | ||
| debug: false |
There was a problem hiding this comment.
hm not sure about this change, I wonder what { request: ['error'] } used to do
There was a problem hiding this comment.
it was originally false only
lib/server/web.js
Outdated
| port: config.server.port, | ||
| cache: cache, | ||
| debug: false, | ||
| debug: { request: ['error'] }, |
lib/server/web.js
Outdated
| // server method for caching profile | ||
| try { | ||
| await server.register({ | ||
| name: 'fxa-profile-server', |
There was a problem hiding this comment.
maybe we can call this just profileCache
lib/server/web.js
Outdated
| }); | ||
|
|
||
| server.ext('onPreResponse', function(request, next) { | ||
| server.ext('onPreResponse', function(request, h) { |
There was a problem hiding this comment.
we have h.continue below
|
@vladikoff still i am missing something :( |
bin/_static.js
Outdated
|
|
||
| async function create() { | ||
| const server = await require('../lib/server/_static').create(); | ||
| server.start().then(() => { |
There was a problem hiding this comment.
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
lib/routes/avatar/delete.js
Outdated
| return workers.delete(avatar.id); | ||
| } | ||
| }) | ||
| req.server.methods.profileCache.drop(uid) |
There was a problem hiding this comment.
looks like this will fail because this doesn't return
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) |
There was a problem hiding this comment.
this also needs to return otherwise response will be lost
lib/routes/display_name/post.js
Outdated
| }) | ||
| .done(reply, reply); | ||
| }); | ||
| req.server.methods.profileCache.drop(uid) |
There was a problem hiding this comment.
this will fail, no return
lib/routes/display_name/post.js
Outdated
| req.server.methods.profileCache.drop(uid) | ||
| .then(() => { | ||
| const payload = req.payload; | ||
| db.setDisplayName(uid, payload.displayName) |
lib/server/_static.js
Outdated
| switch (request.params.type) { | ||
| case '': | ||
| reply.file(DEFAULT_AVATAR); | ||
| h.file(DEFAULT_AVATAR); |
There was a problem hiding this comment.
should we make h.file a return h.file ?
lib/profileCache.js
Outdated
| return next(null, result, ttl); | ||
| }) | ||
| .catch(next); | ||
| .then(result => { |
There was a problem hiding this comment.
@vladikoff , I have fixed the server stop function but it still didn't work. This method seems to be failing.
lib/profileCache.js
Outdated
| server.methods.profileCache.get.cache.drop(req, cb); | ||
| }); | ||
| }).asCallback(next); | ||
| await server.methods.profileCache.get.cache.drop(req); |
There was a problem hiding this comment.
@vladikoff , this method is not right yet, how do we change it correctly ?
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); | |||
There was a problem hiding this comment.
@vladikoff this line is throwing a 500 error, am I missing something ?
There was a problem hiding this comment.
@deeptibaghel do you get this when running the tests?
.eslintrc
Outdated
| semi: [2, "always"] | ||
|
|
||
| parserOptions: | ||
| ecmaVersion: 2017 |
There was a problem hiding this comment.
let's make this 2018 here
lib/config.js
Outdated
| }, | ||
| serverCache: { | ||
| redis: { | ||
| // name: 'redisCache', |
There was a problem hiding this comment.
what happens here? is this not named anymore? do we delete it?
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 |
There was a problem hiding this comment.
per // Don't wait on promise , we don't want an await here
lib/routes/display_name/post.js
Outdated
| }) | ||
| .done(reply, reply); | ||
| }); | ||
| return req.server.methods.profileCache.drop(uid) |
There was a problem hiding this comment.
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.
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({ |
lib/routes/root.js
Outdated
| handler: function index(req, reply) { | ||
| function sendReply() { | ||
| reply({ | ||
| // response: { |
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); | |||
There was a problem hiding this comment.
@deeptibaghel do you get this when running the tests?
| scope: scope | ||
| }}}; | ||
| return await server.methods.profileCache.get.cache.drop(req); | ||
| return server.methods.profileCache.get.cache.drop(req); |
There was a problem hiding this comment.
@vladikoff the test to upload avatar fails at this point
|
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 |
Fixes #333