@tiscode/node-base
TypeScript icon, indicating that this package has built-in type declarations

0.2.1 • Public • Published

TISCODE Node Base

Version Releases

Version: v0.2.1

  • Hotfix cannot set headers after they are sent

Version: v0.2.0

  • ExpressAuthenticatedHandler with jsonwebtoken
  • ExpressPublicHandler
  • Handlers must implement handle method

Version: v0.1.0

  • HttpServer app with peer support for graphql
  • Http Event Types
  • Express adapter (for Handler constructor and Command Factory constructor)
  • Express default handler and abstract handler
  • Command and Command Factory abstracts
  • iif helper function
  • ifnull helper function

Installation

npm i @tiscode/node-base or yarn add @tiscode/node-base

Usage

How to use ExpressAuthenticatedHandler?
With node-base for direct routes ( post / put / get / delete / patch / all )
import { App } from '@tiscode/node-base';
import MyCommandFactory from './factories/commands/my-command';

const expressAuthenticatedHandler = App.Http.Express.adapter(App.Http.Express.authenticatedHandler, MyCommandFactory);
const app = new App.Http.Server();

app.on('started', () => {
  app.attachRouter({
    path: '/my-endpoint',
    method: 'post', // you can change this to 'put', 'get', 'delete', 'patch' or 'all'
    router: expressAuthenticatedHandler
  });
});

app.listen(3000);
With node-base for use routers
import { Router } from 'express';
import { App } from '@tiscode/node-base';
import MyCommandFactory from './factories/commands/my-command';

const expressAuthenticatedHandler = App.Http.Express.adapter(App.Http.Express.authenticatedHandler, MyCommandFactory);
const app = new App.Http.Server();
const router = Router();

router.post('/my-endpoint', expressAuthenticatedHandler);

app.on('started', () => {
  app.attachRouter({
    path: '/api', // default is '/'
    method: 'use',
    router: expressAuthenticatedHandler
  });
});

app.listen(3000);
With express
import express from 'express';
import { App } from '@tiscode/node-base';
import MyCommandFactory from './factories/commands/my-command';

const expressAuthenticatedHandler = App.Http.Express.adapter(App.Http.Express.authenticatedHandler, MyCommandFactory);
const app = express();
app.post('/my-endpoint', expressAuthenticatedHandler);

app.listen(3000);

Package Sidebar

Install

npm i @tiscode/node-base

Weekly Downloads

1

Version

0.2.1

License

MIT

Unpacked Size

248 kB

Total Files

111

Last publish

Collaborators

  • kamikai