我现在正在做feathersjs聊天应用程序教程,但我基于猫鼬。
没关系,我可以创建用户,验证等等,但是在此时,我想实现Gravatar Hook,当我想启动服务器时,我将成为失败。
我有副本&粘贴了所有代码,这是我运行服务器时的错误。
用户.hook.js
const { authenticate } = require('@feathersjs/authentication').hooks;
const { hashPassword, protect } = require('@feathersjs/authentication-local').hooks;
const gravatar = require('../../hooks/gravatar');
module.exports = {
before: {
all: [],
find: [ authenticate('jwt') ],
get: [ authenticate('jwt') ],
create: [ hashPassword(), gravatar() ],
update: [ hashPassword(), authenticate('jwt') ],
patch: [ hashPassword(), authenticate('jwt') ],
remove: [ authenticate('jwt') ]
},
after: {
all: [
// Make sure the password field is never sent to the client
// Always must be the last hook
protect('password')
],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
},
error: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
}
};
gravatar.js
// Use this hook to manipulate incoming or outgoing data.
// For more information on hooks see: http://docs.feathersjs.com/api/hooks.html
// We need this to create the MD5 hash
const crypto = require('crypto');
// The Gravatar image service
const gravatarUrl = 'https://s.gravatar.com/avatar';
// The size query. Our chat needs 60px images
const query = 's=60';
module.exports = function (options = {}) { // eslint-disable-line no-unused-vars
return async context => {
// The user email
const { email } = context.data;
// Gravatar uses MD5 hashes from an email address to get the image
const hash = crypto.createHash('md5').update(email).digest('hex');
context.data.avatar = `${gravatarUrl}/${hash}?${query}`;
// Best practise, hooks should always return the context
return context;
};
};
错误
/mnt/c/Users/user/Documents/_coding/feathersJSChat/server/src/hooks/gravatar.js:13
return async context => {
^^^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/mnt/c/Users/user/Documents/_coding/feathersJSChat/server/src/services/users/users.hooks.js:5:18)
非常感谢,很抱歉我的英语不好。
就像基本指南一样,聊天应用程序显示的代码仅适用于节点8.0.0(node --version
(或更高版本。更多信息可以在先决条件中找到。