1 | # 🌹 @sharyn/koa
|
2 |
|
3 | [![npm](https://img.shields.io/npm/v/@sharyn/koa.svg)](https://www.npmjs.com/package/@sharyn/koa)
|
4 |
|
5 | This package provides a Koa server.
|
6 |
|
7 | ## 🌹 Install
|
8 |
|
9 | Minimal:
|
10 |
|
11 | ```bash
|
12 | yarn add @sharyn/koa koa koa-router
|
13 | ```
|
14 |
|
15 | Full-featured:
|
16 |
|
17 | ```bash
|
18 | yarn add @sharyn/koa koa koa-router koa-mount koa-static koa-favicon koa-compress
|
19 | ```
|
20 |
|
21 | ## 🌹 Usage
|
22 |
|
23 | ### `startServer, stopServer`
|
24 |
|
25 | ```js
|
26 | import { startServer, stopServer } from '@sharyn/koa'
|
27 |
|
28 | const routing = router => {
|
29 | router.get('*', ctx => {
|
30 | ctx.body = `<!doctype html>
|
31 | <html>
|
32 | <body>
|
33 | Hello world!
|
34 | </body>
|
35 | </html>`
|
36 | })
|
37 | }
|
38 |
|
39 | startServer(routing) // Starts server on port PORT of your env, defaulting to 8000
|
40 |
|
41 |
|
42 | // Mute the output with the silent option or change the port in your tests:
|
43 | setup = () => startServer(routing, { port: 6000, silent: true })
|
44 | teardown = () => stopServer({ port: 6000, silent: true })
|
45 | ```
|