@epiijs/minion

A mini server for small web app.

Usage no npm install needed!

<script type="module">
  import epiijsMinion from 'https://cdn.skypack.dev/@epiijs/minion';
</script>

README

epii-minion

Build Status Coverage Status

A mini server for small web app.

Features

one layer pipeline

(Request)
    /__file/* => static/*.*  | static files
    /__data/* => server/*.js | data actions
(Response)

one app shell for single page

default html =>

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/__file/index.css" />
</head>
<body>
  <div id="app"></div>
  <script src="/__file/index.js"></script>
</body>
</html>

Usage

project like this

(root)
├── client
│   ├── layout.html
│   └── index.js(x)
├── server
│   ├── action1.js
│   └── action2.js
└── static
    └── (files)

install as dependency

npm install --save @epiijs/minion@latest

write data action

You can simply write functions to be called as data action. The name of function will be used as pathname of data action like /__data/functionName.

export function doAction1(input) {
  // input = JSON.parse of POST body
  if (input.arg1) {
    throw new Error('your error');
    // status = 200, output = { error: 'your error' }
  }
  if (input.arg2) {
    return { hello: 'world' };
    // status = 200, output = { model: { hello: 'world' }
  }
  if (input.arg3) {
    return fs.createReadStream(input.arg3);
    // status = 200 for static file output
    // status = 404 for error
  }
  // status = 200, output = {}
}

Then access data action by /__data/doAction1 with POST body.

get more request info

// POST is the simplest choice for data action. 
// However, you can get more request info the 2nd param.
export function doAction2(input, request) {
  // request is http.IncomingMessage
}

output custom response

TODO - will be support

use API to start server

const epiiMinion = require('@epiijs/minion');

let config = {
  name: 'YOUR-APP-NAME',
  port: 9988,
  path: {
    root: __dirname,
    server: 'server',
    static: 'static',
    layout: 'layout.html',
    router: {
      '/short', '/__data/fullActionName',
    },
    aspect: 'aspect.js',
  }
};

// less configuration
config = {
  path: {
    root: __dirname,
  },
};

// start minion server
epiiMinion.startServer(config);

use API to start runner

Runner is the shell of command line for minion server.

Reserved options --help, --fork.

const epiiMinion = require('@epiijs/minion');

let config = {
  name: 'YOUR-APP-NAME',
  help: 'YOUR-APP-HELP-FILE',
};

// start minion runner
epiiMinion.startRunner(config, async ({ command, options }) => {
  // run your server or do sth else
});

Contributing

TODO

Language

TODO