Skip to content
@Goa/Koa Web Server Bundled With Essential Middleware.
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.documentary/section-breaks
.vscode
compile
d
doc
documentary
example
modules
src
test
types
.alamoderc.json
.eslintignore
.eslintrc
.gitignore
CHANGELOG.md
LICENSE
README.md
package.json
yarn.lock

README.md

@idio/idio

npm version

@idio/idio is @Goa/Koa Web Server Bundled With Essential Middleware.

yarn add @idio/idio

Table Of Contents

API

The package is available by importing its default function:

import idio from '@idio/idio'

async idio(
  middlewareConfig?: MiddlewareConfig,
  conf?: Config,
): { app, url, middleware }

Starts the server and returns the app and url properties. The app can be stopped with an async .destroy method implemented on it that closes all connections.

MiddlewareConfig: Middleware configuration for the idio server.

Name Type Description
static StaticOptions koa-static options.
compress CompressOptions koa-compress options.
session SessionOptions koa-session options.

Config: Server configuration object.

Name Type Description Default
port number The port on which to start the server. 5000
host string The host on which to listen. 0.0.0.0
SourceOutput
const { url, app } = await idio({
  session: { use: true, keys: new Keygrip(
    ['hello', 'world']) },
  async middleware(ctx, next) {
    ctx.body = 'hello world'
    await next()
  },
})
http://localhost:5000
hello world

Static

🗂 Read Static Middleware Configuration 🗿 Static Idio

Used to serve static files, such as stylesheets, images, videos, html and everything else. Will perform mime-type lookup to serve the correct content-type in the returned header.

Static sourceThe Output
const { url, app } = await idio({
  static: {
    root: 'example', use: true,
  },
// or multiple locations
  static: [{
    root: ['example'], use: true,
  }, {
    root: ['d'], use: true,
  }],
})
/** http://localhost:65481/app.css */ 

body {
  font-size: larger;
}
<!-- http://localhost:5000/em.svg --> 

<xml></xml>
Show Response Headers
Content-Length: 29
Last-Modified: Thu, 18 Jul 2019 14:34:31 GMT
Cache-Control: max-age=0
Content-Type: text/css; charset=utf-8
Date: Thu, 18 Jul 2019 15:48:12 GMT
Connection: close
Content-Length: 11
Last-Modified: Thu, 18 Jul 2019 14:47:20 GMT
Cache-Control: max-age=0
Content-Type: image/svg+xml
Date: Thu, 18 Jul 2019 15:05:24 GMT
Connection: close

Session

Read Session Configuration

Allows to store data in the .session property of the context. The session is serialised and placed in cookies. When the request contains the cookie, the session will be restored and validated (if signed) against the key.

Session sourceThe Output
const { url, app } = await idio({
  session: { use: true, keys:
    ['hello', 'world'], config: {
    signed: false,
  } },
  async middleware(ctx, next) {
    if (ctx.session.user)
      ctx.body = 'welcome back '
        + ctx.session.user
    else {
      ctx.session.user = 'u'
        +( Math.random() * 1000).toFixed(1)
      ctx.body = 'hello new user'
    }
    await next()
  },
})
http://localhost:5000 

/ hello new user
/ welcome back u683.8

Copyright

(c) Idio 2019

You can’t perform that action at this time.