import { hash } from 'bcrypt'; import fastifyPlugin from 'fastify-plugin'; // 加密 async function encryption(fastify, options) { // 注册swagger插件(新版配置方式) fastify.log.warn('Register Encryption Plugin!'); // 初始化时注册插件 fastify.decorate('hash', (str, salt = 10) => hash(str, salt)); fastify.log.warn('Register Encryption complete!'); } export default fastifyPlugin(encryption);