0.3.6 • Published 6 years ago

blueskyfish-express-context v0.3.6

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

BlueSkyFish Express Context

BlueSkyFish Express Context

A small library for express micro services summarize the request and response.

Helpful classes and functions for create a express micro service.

Breaking Change switch to yarn.

Requirements

Global installed typescript. npm install --global typescript.

The library is written in Typescript. During the installation of the library it will be compiled into Javascript ES2015 modules.

Installation

$ npm install -S blueskyfish-express-context

Dependencies

All libraries from blueskyfish-express-* and depended applications should use the same version of the dependencies node modules.

nameVersion
express4.16.3
lodash4.17.10
moment2.22.1
mysql2.15.0
--------------------------------------
mocha5.1.1
ts-node6.0.3
typescript2.8.3

Usage

// File: action.get-about.ts
import { ActionFunc, IContext } from 'blueskyfish-express-context';

export const name: string = '[about] get about';
export const action: ActionFunc<IContext> = (ctx: IContext) => {
	ctx.sendData({
		version: '1.0.0',
		name: 'Demo',
		title: 'Demo Application'
	});
};

// File: about.module.ts
import * as fromGetAbout from './action.get-about.ts';

export const AboutNames = {
	GET_ABOUT: fromGetAbout.name,
};

export class AboutModule {
	
	static forApp(): IActionPool {
		return new BaseActionPool()
			.addAction(fromGetAbout.name, fromGetAbout.action);
	}
}

// File: app.ts
import * as express from 'express';
import { Log } from 'blueskyfish-express-commons';
import { AboutNames, AboutModule } from './about.module';

const APP_TAG: string = 'demo';
const app: express.Application = express();
const actions: ActionRepository = new ActionRepository()
	.addPool(AboutModule.forApp());

app.get('/about', toRouteHandler(actions, AboutNames.GET_ABOUT));

const server: Http = app.listen(3003, 'localhost', () => {
	Log.info(APP_TAG, 'Demo server is listen @ http://localhost:3003');
});

Env.addShutdown((signal: string) => {
	Log.info(APP_TAG, 'Signal "%s" is receive for shutdown...', signal);
	server.close(() => {
		Log.info(APP_TAG, 'Demo server is stopped');
		Env.exit(0);
	});
});

History

VersionDateDescription
0.3.62018-05-12send stream.
0.3.42018-05-11read and write headers and update libraries. send http status code.
0.3.22018-05-10update libraries and remove deprecated interfaces.
0.3.12018-05-02adjust tsc options.
0.2.12018-05-01switch to yarn
0.1.22018-04-21improve whitelist pattern.add example in readme.md.
0.1.12018-04-20fixed index.d.ts
0.1.02018-04-20add action pool and repository.auth middleware with verify rigorous validation.improve js doc.
0.0.122018-04-13adjust the version of the depended node modules.Add render method to the IContext
0.0.112018-03-20Pump version of blueskyfish-common-mysql.
0.0.102018-02-22adjust the version of the depended node modules.
0.0.92018-02-19adjust the lodash version and use interface IBaseError
0.0.82018-02-14context send error use interface IBaseError.
0.0.72018-02-11request params with string and number (reg.params[0] or req.params['name'])
0.0.62018-01-25get express request values from the IContext; Enable to override HttpContext; add protected actionMap property;
0.0.22018-01-24auth middleware
0.0.12018-01-24Initial the library. It is extract from my other internal projects.

License

The MIT License
Copyright 2018 BlueSkyFish
0.3.6

6 years ago

0.3.5

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.1

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago