GithubHelp home page GithubHelp logo

express-subapp's Introduction

express-subapp

Utility to wrap the properties from a master express app into any number of route based sub apps.

Usage

Basic usage gives the ability to set up route-based sub applications:

var express = require('express');
var subApp = require('express-subapp')(
    function onCreate(app) {
        // optionally, set up the main application
    },
    
    function onSubApp(subApp, app) {
        // optionally, set up any other application
    }
);

// make and return an app
var app = subApp.create(express());

// attach paths as normal
app.get('/path', routeHandler);

// name a context root with a required in app.
// module.exports for some-context.js should be an express app
subApp.route('/some-context', require('./routes/some-context.js'));

// alternatively don't set the root in the subApp, do it manually instead
app.use('/context', subApp.route(require('./routes/context.js')));

More commonly, you would use the following properties to name the properties to copy from the main application into the sub apps:

var subApp = require('express-subapp')(onCreate, onSubApp);

// add the names of any keys in the locals of the main application that should be added to the sub apps
subApp.locals.push('some-key', 'another-key');

// add the names of any 'app.get' properties in the main application to be set on the sub apps 
subApp.merged.push('some-key', 'another-key');

License

MIT, use it, play with it, fork it, make pull requests at will.

express-subapp's People

Contributors

steveukx avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.