@feathers-micro/microservice
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

This library is part of the feathers-micro library.

Check the repository for a working example.

@feathers-micro/microservice

Create services in your application that will proxy the calls to your feathers serveless applications.

It's expected that you already have a feathers serverless application configured and running to be able to use this library.

This library only support feathers koa for now, it might work with feathers express but it was not tested.

Usage

# create a feathers application
npm create feathers@latest my-serverless-component

# install the library in your project
yarn add @feathers-micro/microservice

Create a normal feathers service in your application

npx feathers generate service

Update your service with the MicroService class

...

import { MicroService, MicroServiceOptions } from '@feathers-micro/microservice'

...

export class TodoService<ServiceParams extends Params = TodoParams> extends MicroService<
  Todo,
  TodoData,
  TodoParams,
  TodoPatch
> {}

export const getOptions = (app: Application): MicroServiceOptions => {
  return {
    path: 'todo', // service path on the serverless application
    url: 'http://localhost:3020/dev', // url of the serverless application
    getParamsFromBody: false // if you configured your serverless application as a single endpoint mark the property as true
  }
}

You can create resolvers and hooks as with any normal feathers service.

To check a functional setup, look at the example apps.

Authentication

If you want to have your authentication as a serverless application, configure your authentication.ts file.

import { AuthenticationService } from '@feathersjs/authentication'
import { MicroAuthentication } from '@feathers-micro/microservice'

import type { Application } from './declarations'

declare module './declarations' {
  interface ServiceTypes {
    authentication: AuthenticationService
  }
}

export const authentication = (app: Application) => {
  const authentication = new MicroAuthentication(app, 'authentication', { url: 'http://localhost:3010/dev', getParamsFromBody: true })
  // @ts-ignore
  app.use('authentication', authentication)
}

Session ID

When dealing with micro services logging is one of the biggest difficulties, is important to have a tracer id from one component to the other to understand the flow of each call.

To configure a session id on your service calls update your app.ts, this feature is only supported in feathers koa.

...

import { setKoaGateway } from '@feathers-micro/microservice'

...

app.configure(setKoaGateway([app.get('authentication')?.secret ?? '']))

Readme

Keywords

none

Package Sidebar

Install

npm i @feathers-micro/microservice

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

426 kB

Total Files

46

Last publish

Collaborators

  • guzz-junqueira