简体   繁体   中英

Nodejs on azure : server not starting before the first request

I have a weird probleme, when starting listening I run the following function :

app.listen(process.env.PORT || 3000, async function () {
  await db.init().catch(err => {
    console.error(err);
    console.error("Shutting down because there was an error setting up the database.");
    process.exit(1);
  });
  await recordsDb.init().catch(err => {
    console.error(err);
    console.error("Shutting down because there was an error setting up the records database.");
    process.exit(1);
  });
  //this db object will be used by controllers..
  app.set('db',db);
});

the problem is that the function doesn't run before the first request (and so the first request always fail), am I missing something ?
Thank you!

You will need to first scale up your Web App Service plan, then you can enable Always On . By default, apps are unloaded if they are idle for some period of time. This lets the system conserve resources. In Basic or Standard mode, you can enable Always On to keep the app loaded all the time. If your app runs continuous WebJobs or runs WebJobs triggered using a CRON expression, you should enable Always On, or the web jobs may not run reliably. Free Azure web apps do not support Always On.

https://docs.microsoft.com/en-us/azure/app-service/web-sites-configure

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM