Skip to content

kisiwu/novice-app

Repository files navigation

@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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published