Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

Latest commit

 

History

History

tessellate-server

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

tessellate-server

Web service runtime for tessellate services.

TessellateServer

import { TessellateServer } from 'tessellate-server'
constructor(options: Options = {})
use(middleware: Middleware, defer: boolean = false): TessellateServer

Add koa Middleware that runs before any routes are handled. If defer is set to true, the middleware will run after all routes. Also see koa.app.use.

start(port: number | string, metricsPort?: number | string): Promise

Start the koa application server and prometheus metrics server on the specified ports. The default value for metricsPort is port + 1.

TessellateServer.router

koa-rx-router instance. Use it to add routes.

stop(): Promise

Stop all koa servers.

nconf

import { nconf } from 'tessellate-server'

Wrapper around nconf with default values and convenience methods.

  • set(key: string, value: any) - see nconf
  • get(key: string) - see nconf
  • getObject(key: string): Object - see get
  • getString(key: string): string - see get
  • argv(args: Object) - see nconf
  • defaults(defaults: Object) - see nconf

Problem

import { Problem } from 'tessellate-server'

A throwable Error class modeled after Zalando Problem.

Example

Run npm start or check out the code below:

import { TessellateServer, Problem } from '../src'
import { Observable } from 'rxjs'

const server = new TessellateServer()

server.use((ctx, next) => {
  console.log('Hi, this is middleware.')
  return next()
})

server.router.get('/', o => o.mapTo('Hello!'))

server.router.get('/error', o => o.switchMapTo(Observable.throw(
  new Problem({
    title: 'Teapot',
    detail: 'I am a teapot.',
    status: 418
  }))
))

server.start(3001)