UNPKG

905 BMarkdownView Raw
1# 🌹 @sharyn/koa
2
3[![npm](https://img.shields.io/npm/v/@sharyn/koa.svg)](https://www.npmjs.com/package/@sharyn/koa)
4
5This package provides a Koa server.
6
7## 🌹 Install
8
9Minimal:
10
11```bash
12yarn add @sharyn/koa koa koa-router
13```
14
15Full-featured:
16
17```bash
18yarn 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
26import { startServer, stopServer } from '@sharyn/koa'
27
28const 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
39startServer(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:
43setup = () => startServer(routing, { port: 6000, silent: true })
44teardown = () => stopServer({ port: 6000, silent: true })
45```