javascript - How to redirect user with database callback function - HAPI -
i want user shown loading icon until database responds, redirected correct page.
my code along lines of:
// handler function handler(request, reply) { reply.view('loading') // show loading css // database stuff... // database callback function function db_callback_function() { reply.redirect('user/page') // after db responds, redirect. } }
hapi says can use reply interface once:
unhandled promise rejection (rejection id: 1): error: reply interface called twice
so how can redirect user after database loads?
edit: know need show loader using front end. don't know how end tell front end when redirect.
one request can respond once. should "loading stuff" on frontend side not backend.
so when sent http request should mark state loading.
for example code, server code should modify to:
// handler function handler(request, reply) { // reply.view('loading') <- remove line // database stuff... // database callback function function db_callback_function() { reply.redirect('user/page') } }
in case, when frontend received response, redirect appropriate page.
Comments
Post a Comment