1.1.23 • Published 5 years ago
mikudos-node-app v1.1.23
mikudos-node-app
mikudos-node-app is one Building block of Mikudos
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
1.1.23
5 years ago
1.1.22
5 years ago
1.1.21
5 years ago
1.1.20
5 years ago
1.1.19
5 years ago
1.1.18
5 years ago
1.1.17
5 years ago
1.1.16
5 years ago
1.1.15
5 years ago
1.1.14
5 years ago
1.1.13
5 years ago
1.1.12
5 years ago
1.1.11
5 years ago
1.1.9
5 years ago
1.1.10
5 years ago
1.1.8
5 years ago
1.1.7
5 years ago
1.0.17
5 years ago
1.1.6
5 years ago
1.1.5
5 years ago
1.1.4
5 years ago
1.1.3
5 years ago
1.1.2
5 years ago
1.1.1
5 years ago
1.1.0
5 years ago
1.0.16
6 years ago
1.0.15
6 years ago
1.0.14
6 years ago
1.0.11
6 years ago
1.0.10
6 years ago
1.0.13
6 years ago
1.0.12
6 years ago
1.0.9
6 years ago
1.0.8
6 years ago
1.0.7
6 years ago
1.0.6
6 years ago
1.0.5
6 years ago
1.0.4
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago