SyntaxError:意外的令牌返回

SyntaxError: Unexpected token return

本文关键字:令牌 返回 意外 SyntaxError      更新时间:2023-09-26

Epilogue(Sequelize ORM rest endpoint的npm模块)只有5个月的历史,因此文档很少,但我想知道如何使用它的npm页面上的这个示例中间件模块https://www.npmjs.com/package/epilogue

控制台错误读取

     return context.continue;
      ^^^^^^
SyntaxError: Unexpected token return

我正在尝试添加用于身份验证的中间件,我是node/js的新手,刚开始粘贴了示例代码,我不知道如何使用它。

// 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;
      }
    }
  }
};

语法错误。

// 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;
      }
    }
  }
};