This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
772 additions
and
930 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,80 @@ | ||
# tessellate-server | ||
|
||
Web service runtime for tessellate services. | ||
|
||
### TessellateServer | ||
|
||
``` | ||
import { TessellateServer } from 'tessellate-server' | ||
``` | ||
|
||
##### constructor(options: Options = {}) | ||
|
||
* `name: string` Optional application name (see [koa.app.name](https://github.com/koajs/koa/blob/v2.x/docs/api/index.md#settings)) | ||
|
||
##### use(middleware: Middleware, defer: boolean = false): TessellateServer | ||
|
||
Add koa [Middleware](https://github.com/koajs/koa/wiki#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](https://github.com/koajs/koa/blob/v2.x/docs/api/index.md#appusefunction). | ||
|
||
##### start(port: number | string, metricsPort?: number | string): Promise<TessellateServer> | ||
|
||
Start the koa application server and [prometheus](https://github.com/siimon/prom-client) metrics server on the specified ports. The default value for `metricsPort` is `port + 1`. | ||
|
||
#### TessellateServer.router | ||
|
||
[koa-rx-router](https://github.com/mfellner/koa-router-rx) instance. Use it to add routes. | ||
|
||
##### stop(): Promise<any> | ||
|
||
Stop all koa servers. | ||
|
||
### nconf | ||
|
||
```javascript | ||
import { nconf } from 'tessellate-server' | ||
``` | ||
|
||
Wrapper around [nconf](https://github.com/indexzero/nconf) with default values and convenience methods. | ||
|
||
* `set(key: string, value: any)` - see [nconf](https://github.com/indexzero/nconf) | ||
* `get(key: string)` - see [nconf](https://github.com/indexzero/nconf) | ||
* `getObject(key: string): Object` - see `get` | ||
* `getString(key: string): string` - see `get` | ||
* `argv(args: Object)` - see [nconf](https://github.com/indexzero/nconf#argv) | ||
* `defaults(defaults: Object)` - see [nconf](https://github.com/indexzero/nconf) | ||
|
||
### Problem | ||
|
||
```javascript | ||
import { Problem } from 'tessellate-server' | ||
``` | ||
|
||
A throwable Error class modeled after [Zalando Problem](https://github.com/zalando/problem). | ||
|
||
### Example | ||
|
||
Run `npm start` or check out the code below: | ||
|
||
```javascript | ||
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) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Example config file | ||
FOO: bar | ||
BAR: | ||
what: is | ||
code: 42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,23 @@ | ||
// @flow | ||
|
||
import { TessellateServer } from '../src' | ||
import { TessellateServer, Problem } from '../src' | ||
import { Observable } from 'rxjs' | ||
|
||
const server = new TessellateServer() | ||
|
||
server.router.get('/', observable => observable.mapTo('Hello, tessellate!')) | ||
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) | ||
console.log('listening on http://localhost:3001') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.