Next.js: What is on-demand-entries-ping used for?

Created on 30 May 2017  路  6Comments  路  Source: vercel/next.js

Just curious, what is the on-demand-entries-ping doing? It seems be happening every 5 or so seconds.

Is it normal or a bad implementation on my end that on every ping from on-demand-entries-ping a session is being stored in my mongodb sessions table (using https://github.com/jdesboeufs/connect-mongo)? I'm new to BE dev and express so i'm not 100% sure of the implications of that happening.

Thanks!

Most helpful comment

Next.js only build (and watch files) for your current active page (eg pages/index.js in /), that way your project can be huge and it's not going to use a lot of memory for HMR. That endpoint it's used for this feature, that way Next.js know which page you are developing.

All 6 comments

Next.js only build (and watch files) for your current active page (eg pages/index.js in /), that way your project can be huge and it's not going to use a lot of memory for HMR. That endpoint it's used for this feature, that way Next.js know which page you are developing.

Thanks @sergiodxa

@bliitzkrieg It's dev only. If you need, you can bypass that request from sessions stuff.

would this be the proper way to do so?

const server = express();
server.use((req, res, next) => {
    if (opts.dev && req.path.match(/_next\/on-demand-entries-ping/)) {
      return next();
    }
    // session logic here
    // ex:   server.use(session({ ... })) ...
});
server.listen(3000)

@juhaelee I believe express's server.use accepts a string as first argument so you can do server.use('some/path', session())

@juhaelee the first argument to express middleware can also accept a regex. This is how I'm using it:

server.use(/\/((?!_next\/on-demand-entries-ping).)*/, session({
    // initialize express session here
}))

@msenevir you can ignore anything starts with /_next/ and /static/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

knipferrc picture knipferrc  路  3Comments

ghost picture ghost  路  3Comments

YarivGilad picture YarivGilad  路  3Comments

rauchg picture rauchg  路  3Comments

timneutkens picture timneutkens  路  3Comments