当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Application.use方法代码示例

本文整理汇总了TypeScript中@feathersjs/feathers.Application.use方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Application.use方法的具体用法?TypeScript Application.use怎么用?TypeScript Application.use使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@feathersjs/feathers.Application的用法示例。


在下文中一共展示了Application.use方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: default

export default (app: Application) => {
  const authentication = new AuthenticationService(app);

  app.set('authentication', {
    entity: 'user',
    service: 'users',
    secret: 'supersecret',
    authStrategies: [ 'local', 'jwt' ],
    local: {
      usernameField: 'email',
      passwordField: 'password'
    }
  });

  authentication.register('jwt', new JWTStrategy());
  authentication.register('local', new LocalStrategy());

  app.use('/authentication', authentication);
  app.use('/users', memory({
    paginate: {
      default: 10,
      max: 20
    }
  }));

  app.service('users').hooks({
    before: {
      create: hashPassword('password')
    },
    after: protect('password')
  });

  app.use('/dummy', {
    find (params) {
      return Promise.resolve(params);
    }
  });

  app.service('dummy').hooks({
    before: authenticate('jwt')
  });

  app.service('users').hooks({
    before (context: HookContext) {
      if (context.id !== undefined && context.id !== null) {
        context.id = parseInt(context.id as string, 10);
      }

      return context;
    }
  });

  return app;
};
开发者ID:feathersjs,项目名称:feathers,代码行数:54,代码来源:fixture.ts

示例2: beforeEach

  beforeEach(() => {
    app = feathers();
    app.use('/authentication', new AuthenticationService(app, 'authentication', {
      entity: 'user',
      service: 'users',
      secret: 'supersecret',
      authStrategies: [ 'first' ]
    }));
    app.use('/users', memory());

    app.service('authentication').register('first', new Strategy1());
  });
开发者ID:feathersjs,项目名称:feathers,代码行数:12,代码来源:service.test.ts

示例3: beforeEach

  beforeEach(async () => {
    app = feathers();

    const authService = new AuthenticationService(app, 'authentication', {
      entity: 'user',
      service: 'users',
      secret: 'supersecret',
      authStrategies: [ 'jwt' ]
    });

    authService.register('jwt', new JWTStrategy());

    app.use('/users', memory());
    app.use('/protected', {
      async get (id, params) {
        return {
          id, params
        };
      }
    });
    app.use('/authentication', authService);

    const service = app.service('authentication');

    app.service('protected').hooks({
      before: {
        all: [ authenticate('jwt') ]
      }
    });

    app.service('users').hooks({
      after: {
        get: [context => {
          if (context.params.provider) {
            context.result.isExternal = true;
          }

          return context;
        }]
      }
    });

    user = await app.service('users').create({
      name: 'David'
    });

    accessToken = await service.createAccessToken({}, {
      subject: `${user.id}`
    });

    payload = await service.verifyAccessToken(accessToken);
  });
开发者ID:feathersjs,项目名称:feathers,代码行数:52,代码来源:jwt.test.ts

示例4: it

      it('merges params with connection and passes connection', done => {
        const connection = {
          testing: true
        };
        const callback = (error: any, result: any) => {
          if (error) {
            return done(error);
          }

          assert.deepStrictEqual(result, {
            id: 10,
            params: {
              connection,
              query: {},
              route: {},
              testing: true
            }
          });
          done();
        };

        app.use('/otherservice', {
          get (id, params) {
            return Promise.resolve({ id, params });
          }
        });

        runMethod(app, connection, 'otherservice', 'get', [ 10, {}, callback ]);
      });
开发者ID:feathersjs,项目名称:feathers,代码行数:29,代码来源:utils.test.ts

示例5: beforeEach

    beforeEach(() => {
      app.use('/test', {
        events: [ 'foo' ],

        create (payload: any) {
          return Promise.resolve(payload);
        }
      });
    });
开发者ID:feathersjs,项目名称:feathers,代码行数:9,代码来源:dispatch.test.ts

示例6: beforeEach

  beforeEach(() => {
    app = feathers().configure(routing());

    app.use('/my/service', {
      get (id: string|number) {
        return Promise.resolve({ id });
      }
    });
  });
开发者ID:feathersjs,项目名称:feathers,代码行数:9,代码来源:routing.test.ts

示例7: it

    it('passes when entity service exists and `entityId` property is set', () => {
      app.get('authentication').entityId = 'id';
      app.use('/users', {
        async get () {
          return {};
        }
      });

      app.setup();
    });
开发者ID:feathersjs,项目名称:feathers,代码行数:10,代码来源:service.test.ts

示例8: beforeEach

 beforeEach(() => {
   app = feathers().configure(routing());
   app.use('/myservice', {
     get (id: number|string, params: Params) {
       if (params.query.error) {
         return Promise.reject(new errors.NotAuthenticated('None shall pass'));
       }
       return Promise.resolve({ id });
     }
   });
 });
开发者ID:feathersjs,项目名称:feathers,代码行数:11,代码来源:utils.test.ts

示例9: beforeEach

  beforeEach(() => {
    app = feathers();
    app.use('/authentication', new AuthenticationService(app, 'authentication', {
      entity: 'user',
      service: 'users',
      secret: 'supersecret',
      authStrategies: [ 'first' ]
    }));
    app.use('/auth-v2', new AuthenticationService(app, 'auth-v2', {
      entity: 'user',
      service: 'users',
      secret: 'supersecret',
      authStrategies: [ 'test' ]
    }));
    app.use('/users', {
      async find () {
        return [];
      },

      async get (_id: string|number, params: Params) {
        return params;
      }
    });

    const service = app.service('authentication');

    service.register('first', new Strategy1());
    service.register('second', new Strategy2());

    app.service('auth-v2').register('test', new Strategy1());

    app.service('users').hooks({
      before: {
        get: authenticate('first', 'second')
      }
    });

    app.service('users').id = 'name';
    app.setup();
  });
开发者ID:feathersjs,项目名称:feathers,代码行数:40,代码来源:authenticate.test.ts

示例10: beforeEach

  beforeEach(() => {
    app = feathers();

    app.configure(client());
    app.use('/authentication', {
      create (data) {
        return Promise.resolve({
          accessToken,
          data,
          user
        });
      },

      remove (id) {
        return Promise.resolve({ id });
      }
    });
    app.use('dummy', {
      find (params) {
        return Promise.resolve(params);
      }
    });
  });
开发者ID:feathersjs,项目名称:feathers,代码行数:23,代码来源:index.test.ts


注:本文中的@feathersjs/feathers.Application.use方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。