本文整理汇总了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;
};
示例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());
});
示例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);
});
示例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 ]);
});
示例5: beforeEach
beforeEach(() => {
app.use('/test', {
events: [ 'foo' ],
create (payload: any) {
return Promise.resolve(payload);
}
});
});
示例6: beforeEach
beforeEach(() => {
app = feathers().configure(routing());
app.use('/my/service', {
get (id: string|number) {
return Promise.resolve({ id });
}
});
});
示例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();
});
示例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 });
}
});
});
示例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();
});
示例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);
}
});
});