简体   繁体   中英

SyntaxError: Unexpected token return

Epilogue (npm module for Sequelize ORM rest endpoints) is only 5 months old hence the sparse documentation but I was wondering how to work with this sample middleware module that was on it's npm page https://www.npmjs.com/package/epilogue

Console error read

     return context.continue;
      ^^^^^^

SyntaxError: Unexpected token return

I'm trying to add middleware for authentication and I'm new to node/js and just pasted the sample code to start with, and I'm not sure how to work with this.

// middleware.js
module.exports = {
  create: {
    fetch: function(req, res, context) {
    // manipulate the fetch call

    console.log('Request URL:', req.originalUrl);
        next();
    }, function (req, res, next) {

        console.log('Request Type:', req.method);
        next();
    }

      return context.continue;
    }
  },
  list: {
    write: {
      before: function(req, res, context) {
        // modify data before writing list data
        return context.continue;
      },
      action: function(req, res, context) {
        // change behavior of actually writing the data
        return context.continue;
      },
      after: function(req, res, context) {
        // set some sort of flag after writing list data
        return context.continue;
      }
    }
  }
};

Bad syntax.

// middleware.js
module.exports = {
  create: {
    fetch: function(req, res, context) {
    // manipulate the fetch call

        console.log('Request URL:', req.originalUrl);
        console.log('Request Type:', req.method);


      return context.continue;
    }
  },
  list: {
    write: {
      before: function(req, res, context) {
        // modify data before writing list data
        return context.continue;
      },
      action: function(req, res, context) {
        // change behavior of actually writing the data
        return context.continue;
      },
      after: function(req, res, context) {
        // set some sort of flag after writing list data
        return context.continue;
      }
    }
  }
};

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