-
Notifications
You must be signed in to change notification settings - Fork 23
[WIP] refactor(hapi): Upgrade to hapi 17 #334
base: master
Are you sure you want to change the base?
Conversation
vladikoff
left a comment
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'll check 'static' in a bit
lib/profileCache.js
Outdated
| user: uid, | ||
| scope: scope | ||
| }}}; | ||
| return P.fromCallback(cb => { |
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 is a cb here, should that be removed and function below needs to 'return'?
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.
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.
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'?
lib/routes/avatar/delete.js
Outdated
| }) | ||
| .then(() => { | ||
| notifyProfileUpdated(uid); // Don't wait on promise | ||
| return EMPTY; |
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.
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.
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?
lib/routes/email.js
Outdated
| url: '/v1/_core_profile', | ||
| headers: req.headers, | ||
| credentials: req.auth.credentials | ||
| }, res => { |
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.
no callbacks in inject?
| cors: true, | ||
| security: { | ||
| hsts: { | ||
| maxAge: 15552000, |
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 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(() => {}); |
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.
return?
| server.route(routes); | ||
|
|
||
| server.ext('onPreAuth', function (request, reply) { | ||
| server.ext('onPreAuth', function (request, h) { |
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.
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.
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
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) |
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.
return here as well?
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.
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
bin/worker.js
Outdated
| server.start(function() { | ||
| logger.info('listening', server.info.uri); | ||
| }); | ||
| async function start(){ |
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.
style: start() { (space before {
| cache: { | ||
| expiresIn: options.expiresIn, | ||
| generateTimeout: options.generateTimeout | ||
| generateTimeout: options.generateTimeout || 100 |
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 we change that in the tests instead and should not do this here
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.
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') |
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.
nice 👍
| host: config.server.host, | ||
| port: config.server.port + 1, | ||
| debug: { request: ['error'] } | ||
| debug: false |
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.
hm not sure about this change, I wonder what { request: ['error'] } used to do
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.
it was originally false only
lib/server/web.js
Outdated
| port: config.server.port, | ||
| cache: cache, | ||
| debug: false, | ||
| debug: { request: ['error'] }, |
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.
ahh
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.
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
lib/server/web.js
Outdated
| }); | ||
|
|
||
| server.ext('onPreResponse', function(request, next) { | ||
| server.ext('onPreResponse', function(request, h) { |
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.
do we need the h here?
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.
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.
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
lib/routes/avatar/delete.js
Outdated
| return workers.delete(avatar.id); | ||
| } | ||
| }) | ||
| req.server.methods.profileCache.drop(uid) |
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.
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.
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
lib/routes/display_name/post.js
Outdated
| }) | ||
| .done(reply, reply); | ||
| }); | ||
| req.server.methods.profileCache.drop(uid) |
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.
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) |
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 return here too
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.
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 ?
lib/profileCache.js
Outdated
| return next(null, result, ttl); | ||
| }) | ||
| .catch(next); | ||
| .then(result => { |
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.
@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.
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 ?
lib/profileCache.js
Outdated
| user: uid, | ||
| scope: scope | ||
| }}}; | ||
| return await server.methods.profileCache.get.cache.drop(req); |
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.
@vladikoff this line is throwing a 500 error, am I missing something ?
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.
@deeptibaghel do you get this when running the tests?
.eslintrc
Outdated
| semi: [2, "always"] | ||
|
|
||
| parserOptions: | ||
| ecmaVersion: 2017 |
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.
let's make this 2018 here
lib/config.js
Outdated
| }, | ||
| serverCache: { | ||
| redis: { | ||
| // name: 'redisCache', |
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.
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.
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
lib/routes/display_name/post.js
Outdated
| }) | ||
| .done(reply, reply); | ||
| }); | ||
| return req.server.methods.profileCache.drop(uid) |
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.
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({ |
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.
should we throw here?
lib/routes/root.js
Outdated
| handler: function index(req, reply) { | ||
| function sendReply() { | ||
| reply({ | ||
| // response: { |
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.
what happened here?
lib/profileCache.js
Outdated
| user: uid, | ||
| scope: scope | ||
| }}}; | ||
| return await server.methods.profileCache.get.cache.drop(req); |
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.
@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.
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
|
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