0.3.2 • Published 1 month ago

@novice1/app v0.3.2

Weekly downloads
1
License
MIT
Repository
github
Last release
1 month ago

@novice1/app

Create Express applications.

Installation

$ npm install @novice1/app

Usage

const routing = require('@novice1/routing'),
  { FrameworkApp } = require('@novice1/app');

// Router
const router = routing().get('/', (req, res) => {
  // ...
}).put('/', (req, res) => {
  // ...
});

// FrameworkApp
const app = new FrameworkApp({
  framework: {
    // middlewares
    middlewares: [
      (req, res, next) => {
        next();
      }
    ],
    // authorization middlewares
    auth: [
      (req, res, next) => {
        next();
      }
    ],
    // validation middlewares
    validators: [
      (req, res, next) => {
        next();
      }
    ]
  },
  // routers
  routers: [
    router
  ]
});

// http.Server
const server = app.listen(8000, '0.0.0.0', () => {
  console.log('Application started ...');
  console.log(app.meta)
});

addOptions

Concatenate current application options with new options.

app.addOptions({
  // add more routers
  routers: [router]
});

Routing

app.addRouters([router]);
app.get({
  path: '/index',
  name: 'Home',
  tags: ['Index']
}, function homepage(req, res) {
  // ...
});

app.put('/add', (req, res) => {
  // ...
});

app.use((err, req, res) => {
  // ...
});
const lazyRouter = app.lazyrouter();
lazyRouter.get({
  path: '/index',
  name: 'Home',
  tags: ['Index']
}, function homepage(req, res) {
  // ...
});

lazyRouter.put('/add', (req, res) => {
  // ...
});

lazyRouter.use((err, req, res) => {
  // ...
});

http ServerOptions

const httpServerOptions = {};

const server = app.build(httpServerOptions);
server.listen(8000, '0.0.0.0', () => {
  console.log('Application started ...');
  console.log(app.meta)
});
const https = require('https');
const httpsServerOptions = {};

const server = app.build(httpsServerOptions, https);
server.listen(8000);

References

0.3.2

1 month ago

0.3.0

9 months ago

0.3.1

9 months ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago

0.1.1

3 years ago

0.0.4

4 years ago

0.0.1

4 years ago