E
E
Egor Mikheev2017-04-27 20:39:23
Node.js
Egor Mikheev, 2017-04-27 20:39:23

Why does a 404 error return every other time?

I use connect + connect-rest plugins, essentially the same express.
Faced with an incomprehensible situation with a given route for the first time returns a correct response, with a second request 404, the next request is again correct. With what such situation can be connected?
index.js

// REST SERVICE
require('./utils/rest')(app);


// 404 catch-all handler (middleware)
app.use((req, res) => {
    logger.info('404');
    //res.statusCode = 404;
    return res.end('rewss');
});

// 500 error handler (middleware)
app.use((err, req, res) => {
    console.error(err.stack);
    logger.info('500');
    //res.statusCode = 500;
    return res.end('500');
});

utils/rest.js
const rest = require('connect-rest').create(apiOptions);

    app.use(rest.processRequest());

    // Using auth routes
    require('../routes/sessions').registerRoutes(rest);

/routes/session.js
module.exports = {

    registerRoutes: function (rest) {
        rest.get(/^\/session(.json)?$/g, this.session_start_app);
    },

    session_start_app: function (req, content, cb) {

       return cb( null, "privet"
            , { statusCode: 201,
                headers: {
                ETag: "10c24bc-4ab-457e1c1f"
            }});
...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question