@cat-org/server

Run koa server with pipeline

WARNING: This project has been renamed to @mikojs. Install using @mikojs instead.
Last updated 9 months ago by cat-org .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install @cat-org/server 
SYNC missed versions from official npm registry.

@cat-org/server · npm npm-size

Run koa server with pipeline and babel. This package is just a helper. You can replace any method in @cat-org/server by using the custom functions.

Install

yarn add koa @cat-org/server

Run command

This command is base on babel. You can use any babel command expect for yarn server ./src/server.js. If you want to use the default server, you need to have a soruce folder. For example:

yarn server src -d lib

If you want to use the custom server, you need to add a custom server file, For example:

import server form '@cat-org/server';

export default () =>
  server.init()
    |> server.run()

And run with:

yarn server ./src/server.js -o ./lib/server.js
Environment variables
  • PORT: Set the port of the server
  • NODE_ENV: Set the dev mode or not.

Use default server in testing

import server from '@cat-org/server/lib/defaults';

let runningServer;

describe('server', () => {
  beforeAll(async () => {
    runningServer = await server({
      src: './path-to-src-folder',
      dir: './path-to-dir-folder',
    });
  });

  afterAll(() => {
    runningServer.close();
  });
});

Write the custom server

import server from '@cat-org/server';

export default ({ src, dir, dev, watch, port }) =>
  server.init()
  |> server.use(async (ctx, next) => {
    await next();
  })
  |> ('/path'  // if this is undefined, this will not add prefix to router
    |> server.start
    |> ('/get'
    |> server.get  // this will render as /path/get with get method (post, put, del, all)
      |> server.use(async (ctx, next) => {
        await next();
      })
      |> server.end)
    |> server.use(async (ctx, next) => {
      await next();
    })
    |> server.end)
  |> (undefined
    |> server.start
    |> ('/get'  // this will render as /get with get method
      |> server.get
      |> server.end)
    |> server.end)
  |> server.run()
  |> server.watch(dir, []);
  • init: Just use to return Koa. You can replace by new Koa().
  • use: Add middleware to the router or the server.
  • start, end: Add a new router.
  • get, post, put, del, all: Add method to this router.
  • run: Just use to return a promise with new Koa().listen(port). The default of the port is 8000.
  • watch: Use this function to watch the changed file. This method is based on chokidar. You can write the same function by yourself. If you want to add the function to handle the changed file, you can add an array in the second argument.

Load plugins with default server

You can add those packages in your project and @cat-org/server will load the default config for those modules.

  • @cat-org/koa-base
  • @cat-org/koa-graphql
  • @cat-org/koa-react
    • @cat-org/use-css
    • @cat-org/use-less

You only need to do this:

yarn add @cat-org/package-name

Environment variables about those plugins

  • Run command without building js in the production mode.
SKIP_BUILD=true NODE_ENV=production yarn server src -d lib
  • Run command without running relay-compiler.
SKIP_RELAY=true yarn server src -d lib
  • Run command without running server.
SKIP_SERVER=true yarn server src -d lib

Current Tags

  • 1.0.0-beta.24                                ...           beta (a year ago)
  • 1.5.8                                ...           latest (9 months ago)

22 Versions

  • 1.5.8 [deprecated]           ...           9 months ago
  • 1.5.7 [deprecated]           ...           9 months ago
  • 1.5.6 [deprecated]           ...           9 months ago
  • 1.5.4 [deprecated]           ...           9 months ago
  • 1.5.3 [deprecated]           ...           9 months ago
  • 1.5.2 [deprecated]           ...           9 months ago
  • 1.5.0 [deprecated]           ...           a year ago
  • 1.4.0 [deprecated]           ...           a year ago
  • 1.3.1 [deprecated]           ...           a year ago
  • 1.3.0 [deprecated]           ...           a year ago
  • 1.2.2 [deprecated]           ...           a year ago
  • 1.2.1 [deprecated]           ...           a year ago
  • 1.2.0 [deprecated]           ...           a year ago
  • 1.1.5 [deprecated]           ...           a year ago
  • 1.1.1 [deprecated]           ...           a year ago
  • 1.0.0 [deprecated]           ...           a year ago
  • 1.0.0-beta.24                                ...           a year ago
  • 1.0.0-beta.20                                ...           a year ago
  • 1.0.0-beta.19                                ...           a year ago
  • 1.0.0-beta.17                                ...           a year ago
  • 1.0.0-beta.16                                ...           a year ago
  • 1.0.0-beta.14                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 22
This Month 22
Last Day 0
Last Week 0
Last Month 28
Dependencies (13)
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |