@z1/preset-feathers-server-core

0.5.22 • Public • Published

Z1 Preset Feathers Server Core

Documentation under construction.

Dependencies

Usage

Install

yarn add @z1/preset-feathers-server-core

Import

import {  
  Feathers,
  FeathersExpress,
  FeathersSocketIO,
  FeathersErrors,
  FeathersConfig,
  FeathersAuth,
  FeathersAuthLocal,
  FeathersOAuth,
  FeathersLogger,
  FeathersCommonHooks,
  FeathersAuthHooks,
  Cors,
  Compression,
  Winston
} from '@z1/preset-feathers-server-core'

Example

// Feathers
const app = Feathers();

// FeathersExpress
const app = FeathersExpress(Feathers());

// FeathersSocketIO
app.configure(FeathersSocketIO());

// FeathersConfig
app.configure(FeathersConfig())

// FeathersErrors
if(!condition)
  throw new FeathersErrors.NotFound('User does not exist');

if(!condition)
  throw new FeathersErrors.GeneralError(`${message}`);

// FeathersAuth

const authentication = new FeathersAuth.AuthenticationService(app)
authentication.register('jwt', new FeathersAuth.JWTStrategy())
authentication.register('local', new FeathersAuthLocal.LocalStrategy())
app.set('authenticationService', authentication)

// FeathersOAuth
app.configure(FeathersOAuth.expressOauth())


// FeathersLogger
app.configure(FeathersLogger())


// FeathersCommonHooks
const hooks = {
  before: {
    all: FeathersCommonHooks.cache(cacheMap)
  },
  after: {
    all: FeathersCommonHooks.cache(cacheMap)
  }
}

// FeathersAuthHooks
app.service('users').hooks({
  before: {
    all: [
      FeathersAuth.JWTStrategy(),
      FeathersAuthHooks.setField({
        from: 'params.user.id',
        as: 'params.query.id'
      })
    ]
  }
})

// Cors
app.use(Cors())

// Compression
app.use(Compression({ filter: Boolean }))

// Winston
const levels = {
  error: 0,
  warn: 1,
  info: 2,
  http: 3,
  verbose: 4,
  debug: 5,
  silly: 6
};

const logger = Winston.createLogger({
  level: levels,
  levels: Winston.config.npm.levels,
  format: Winston.format.json,
  transports: Array,
  exitOnError: Boolean,
  silent: Boolean
});

Readme

Keywords

none

Package Sidebar

Install

npm i @z1/preset-feathers-server-core

Weekly Downloads

103

Version

0.5.22

License

MIT

Unpacked Size

21.9 kB

Total Files

4

Last publish

Collaborators

  • nubuck