# sg-server

> HTTP server for SUGOS

Latest version **2.0.2** (published 2018-02-27) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install sg-server
pnpm add sg-server
yarn add sg-server
bun add sg-server
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2018-02-27 |
| First published | 2017-01-31 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=7.6 |
| Dependencies | 8 |
| Unpacked size | 22 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Taka Okunishi |
| Maintainers | realglobe |
| Keywords | SUGOS, web |

## Links

- npm: https://www.npmjs.com/package/sg-server
- Repository: https://github.com/realglobe-Inc/sg-server
- Homepage: https://github.com/realglobe-Inc/sg-server#readme
- Issues: https://github.com/realglobe-Inc/sg-server/issues
- npm.io page: https://npm.io/package/sg-server

## Dependencies (8)

- [koa](https://npm.io/package/koa.md) ^2.5.0
- [aport](https://npm.io/package/aport.md) ^2.0.0
- [arequest](https://npm.io/package/arequest.md) ^3.0.0
- [koa-range](https://npm.io/package/koa-range.md) ^0.3.0
- [koa-router](https://npm.io/package/koa-router.md) ^7.4.0
- [koa-static](https://npm.io/package/koa-static.md) ^4.0.2
- [koa-compose](https://npm.io/package/koa-compose.md) ^4.0.0
- [koa-bodyparser](https://npm.io/package/koa-bodyparser.md) ^4.2.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 2.0.2 (latest) — 2018-02-27
- 2.0.1 — 2017-09-17
- 1.6.1 — 2017-04-26
- 1.5.1 — 2017-04-11
- 1.4.3 — 2017-01-31

## README

sg-server
==========

<!---
This file is generated by ape-tmpl. Do not update manually.
--->

<!-- Badge Start -->
<a name="badges"></a>

[![Build Status][bd_travis_shield_url]][bd_travis_url]
[![npm Version][bd_npm_shield_url]][bd_npm_url]
[![JS Standard][bd_standard_shield_url]][bd_standard_url]

[bd_repo_url]: https://github.com/realglobe-Inc/sg-server
[bd_travis_url]: http://travis-ci.org/realglobe-Inc/sg-server
[bd_travis_shield_url]: http://img.shields.io/travis/realglobe-Inc/sg-server.svg?style=flat
[bd_travis_com_url]: http://travis-ci.com/realglobe-Inc/sg-server
[bd_travis_com_shield_url]: https://api.travis-ci.com/realglobe-Inc/sg-server.svg?token=
[bd_license_url]: https://github.com/realglobe-Inc/sg-server/blob/master/LICENSE
[bd_codeclimate_url]: http://codeclimate.com/github/realglobe-Inc/sg-server
[bd_codeclimate_shield_url]: http://img.shields.io/codeclimate/github/realglobe-Inc/sg-server.svg?style=flat
[bd_codeclimate_coverage_shield_url]: http://img.shields.io/codeclimate/coverage/github/realglobe-Inc/sg-server.svg?style=flat
[bd_gemnasium_url]: https://gemnasium.com/realglobe-Inc/sg-server
[bd_gemnasium_shield_url]: https://gemnasium.com/realglobe-Inc/sg-server.svg
[bd_npm_url]: http://www.npmjs.org/package/sg-server
[bd_npm_shield_url]: http://img.shields.io/npm/v/sg-server.svg?style=flat
[bd_standard_url]: http://standardjs.com/
[bd_standard_shield_url]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg

<!-- Badge End -->


<!-- Description Start -->
<a name="description"></a>

HTTP server for SUGOS

<!-- Description End -->


<!-- Overview Start -->
<a name="overview"></a>

Using [koa][koa_url] as a base framework 


<!-- Overview End -->


<!-- Sections Start -->
<a name="sections"></a>

<!-- Section from "doc/guides/01.Installation.md.hbs" Start -->

<a name="section-doc-guides-01-installation-md"></a>

Installation
-----

```bash
$ npm install sg-server --save
```


<!-- Section from "doc/guides/01.Installation.md.hbs" End -->

<!-- Section from "doc/guides/02.Usage.md.hbs" Start -->

<a name="section-doc-guides-02-usage-md"></a>

Usage
---------

```javascript
'use strict'

const sgServer = require('sg-server')
const co = require('co')

co(function * () {
  let server = sgServer({
    /** Static directories to serve */
    static: [ 'public' ],
    /** Koa middlewares to use */
    middlewares: [
      co.wrap(function * customEndpoint (ctx, next) {
        /* ... */
        yield next()
      })
    ],
    /** Endpoint handlers */
    endpoints: {
      '/api/foo/:id': { // Pass object to handle each HTTP verbs
        'POST': (ctx) => {
          let { id } = ctx.params
          ctx.body = `This is foo with id: "${id}"`
        }
      },
      '/api': '/api/index', // Pass string to create alias
      '/api/index': () => { /* ... */ } // Pass function to handle all HTTP verbs
    }
  })

  yield server.listen(3000)

  // To close server.
  // yield server.close()
}).catch((err) => console.error(err))

```


<!-- Section from "doc/guides/02.Usage.md.hbs" End -->

<!-- Section from "doc/guides/03.Signature.md.hbs" Start -->

<a name="section-doc-guides-03-signature-md"></a>

Signature
-------

#### sgServer(config) -> http.Server

Create web server using koa

| Arg | Type | Default | Description |
| --- | ---- | --- | --- |
| config | object  |  | Server configuration |
| config.middlewares | function[]  | [] | Middlewares instance |
| config.keys | string  |  | Koa keys |
| config.context | Object  |  | Koa context prototype |
| config.onError | function  |  | Error handler |
| config.static | string  |  | Public directories. |
| config.endpoints | Object  |  | Endpoint settins |


<!-- Section from "doc/guides/03.Signature.md.hbs" End -->


<!-- Sections Start -->


<!-- LICENSE Start -->
<a name="license"></a>

License
-------
This software is released under the [Apache-2.0 License](https://github.com/realglobe-Inc/sg-server/blob/master/LICENSE).

<!-- LICENSE End -->


<!-- Links Start -->
<a name="links"></a>

Links
------

+ [SUGOS][sugos_url]
+ [koa][koa_url]

[sugos_url]: https://github.com/realglobe-Inc/sugos
[koa_url]: https://github.com/koajs/koa

<!-- Links End -->

---
_Source: https://npm.io/package/sg-server · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
