Giter Club home page Giter Club logo

agentk's Introduction

AgentK: Synchronous Node.JS web service framework

features

  • support for new ES6 style module loading
  • write async scripts synchronously
  • intergreted process monitor supporting clusters
  • support for view engines

Getting started

Installation

Open a terminal and type:

npm install kyriosli/agentk -g

If you are using linux/osx, or mingw32 on windows, you can also enable bash/zsh auto completion by typing:

ak completion >> ~/.bashrc (or ~/.zshrc)

Writing code

AgentK uses modern ES6 features including:

It uses Fibers to get around callbacks in Node.JS development. The example below shows a simple http server that returns static file as well as forward proxy web pages (See test/test.js):

// test.js
import {listen, request, read} from '../src/module/http.js';
import * as response from '../src/module/http_response.js';
import Router from '../src/module/router.js';
import * as view from '../src/module/view.js';

const route = new Router();

route.prefix('/static', function (req) {
    console.log(req.timeStart, req.url);
    return response.file(req.url.substr(1))
        .setHeader('Content-Type', 'text/javascript')
        .enableGzip();
});

route.match(/^\/([^\/]+)(\/.*)/, function (req, host, path) {
    console.log(host, path);
    var tres = request({
        method: 'GET',
        host: host,
        path: path
    });
    return response.stream(tres)
        .setStatus(tres.statusCode)
        .setHeaders(tres.headers)
});

let server = listen(3000, route);
console.log('test listening on', server.address());

Type ak run test.js to run the program

Running the program

Agentk can run the program directly, as well as guard its process to prevent system down, and restarts it when the server maching is rebooted. Type ak help to get help message.

Available commands are:

  • help print this help message
  • run run program without crash respawn
  • start start program
  • stop stop program
  • restart restart program
  • reload reload program (partial implemented)
  • status show program status
  • doc generate documentation (not implemented)
  • init initialize project structure (not implemented)
  • publish publish a module
  • logs print program stdout/stderr log message
  • svc-install create init.rc script (not implemented)
  • svc-purge remove init.rc script (not implemented)
  • svc-start start service daemon
  • svc-stop stop service daemon
  • completion auto completion helper

When using ak start program to enable guarding of the process, a manifest.json must be created in the program directory (see test/manifest.json), and the name of the program directory is supplied to the command line.

manifest.json contains:

  • main the entry module path of the program. Default to "index.js"
  • directory the work directory of the program. Default to the program directory
  • workers number of processes to be spawned to run the program, default 1
  • stdout the path of the stdout log file to be appended, default to ~/.agentk/out.log
  • stderr the path of the stderr log file to be appended, default to ~/.agentk/err.log
  • dependencies map the depended modules of the program to is revision.

All paths are relative to the program directory.

Use ak init to create an empty program structure. (NOT implemented)

Writing modules

TODO

Module server

TODO

Publishing modules

TODO

Module auto loading

TODO

agentk's People

Watchers

James Cloos avatar hongyu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.