1.1.23 • Published 4 years ago

mikudos-node-app v1.1.23

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Mikudos Service

Mikudos

mikudos-node-app

mikudos-node-app is one Building block of Mikudos

node version version npm version license downloads collaborators typescript

build on top of Mali.js

The Application self is extended from Mali's Application

Example

A Example implementation of mikudos-node-app in typescript can be found as the linked repository.

Usage

Import the mikudos-node-app module:

import { Application } from 'mikudos-node-app';

const PROTO_PATH = path.resolve(
    __dirname,
    '../proto/game_puzzles/game_puzzles.proto'
);

const app: Application = new Application(PROTO_PATH);

// write a service to handle grpc methods
import {
    Service,
    Method,
    HookMethod,
    HookService,
    App,
    Customer,
} from 'mikudos-node-app';
/**
 * You can find a systematic description for the use case of middleware at: https://mali.js.org/api/#mali-%E2%87%90-emitter
 **/
async function hook1(ctx: any, next: Function) {
    // TransactionManager.commitTransaction
    console.log('GreeterService service hook');
    await next();
}
async function hook2(ctx: any, next: Function) {
    // TransactionManager.commitTransaction
    console.log('SayHello method hook');
    await next();
}

@Service({ name: 'GreeterService', serviceName: 'GreeterService' }) // register the service with name to add the service to app.services[name] at the same time
@HookService('before', hook1) // add one service level before hook
@HookService('after', hook1) // add one service level after hook
export class Greeter {
    constructor(
        @App() private app: Application,
        @Customer('test string') private test: any
    ) {}

    @Method('SayHello') // register method to a grpc method
    @Method('SayHi') // register the same method to an other grpc method
    @HookMethod('before', hook2) // register a method level middleware as before hook
    @HookMethod('before', hook2) // register an other method level middleware as before hook
    @HookMethod('after', hook2) // register a method level middleware as after hook
    async SayHello(ctx: any, next: Function) {
        // the handle method self
        const app = ctx.app;
        ctx.res = { message: 'Hello '.concat(ctx.req.name) };
        next();
    }
}

app.register(Greeter);
// for js implementation should use the version 1.0.16 of mikudos-node-app
var { Application } = require('mikudos-node-app');

const PROTO_PATH = path.resolve(
    __dirname,
    '../proto/game_puzzles/game_puzzles.proto'
);

const app: Application = new Application(PROTO_PATH);

Show Debug info

DEBUG=mikudos:* npm start

License

MIT

1.1.23

4 years ago

1.1.22

4 years ago

1.1.21

4 years ago

1.1.20

4 years ago

1.1.19

4 years ago

1.1.18

4 years ago

1.1.17

4 years ago

1.1.16

4 years ago

1.1.15

4 years ago

1.1.14

4 years ago

1.1.13

4 years ago

1.1.12

4 years ago

1.1.11

4 years ago

1.1.9

4 years ago

1.1.10

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.0.17

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago