2.4.0-2 • Published 8 years ago

@nxus/router v2.4.0-2

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

@nxus/router

Build Status

The Nxus router is an Express compatible web server and router for Nxus applications.

Installation

In your Nxus application:

> npm install @nxus/router --save

Usage

Defining a route

app.get('router').route('/', (req, res) => {
  res.send('Hello World')
})

Alternatively, you can specify a HTTP method:

app.get('router').route('GET', '/', (req, res) => {
  res.send('Hello World')
})

Adding Express/connect middleware

app.get('router').middleware((req, res) => {
  res.status(404).send('Nothing to see here');
})

Adding static files/directories

app.get('router').static("my-prefix", myPath)

For example, myFile.txt in myPath is then available at the url /my-prefix/myFile.txt

Sometimes its good to have a static assets folder where all your assets live. For that reason, you can use the assets gatherer.

API


Router

constructor

Sets up the relevant gather/providers

Parameters

  • app

getExpressApp

Returns the Express App instance.

Returns Instance ExpressJs app instance.

getRoutes

Returns the internal routing table.

Returns array routes which have been registered

launch

Launches the Express app. Called by the app.load event.

setMiddleware

Adds a middleware handler to the internal routing table passed to Express. Accessed with 'middleware' gather.

Parameters

  • route string A URL route.
  • handler function An ExpressJs type callback to handle the route.
  • method (optional, default 'use')

setRoute

Adds a route to the internal routing table passed to Express. Accessed with the 'route' gather.

Parameters

  • method string Either 'get', 'post', 'put' or 'delete'.
  • route string A URL route.
  • handler function An ExpressJs type callback to handle the route.

setStatic

Adds a path to serve static files.

Parameters

  • prefix string The path at which the static files will be accessible. For example: /js
  • path string A fully resolved path.

stop

Stops the express app. Called by the app.stop event.

2.4.0-2

8 years ago

2.4.0-1

8 years ago

2.4.0-0

8 years ago

2.3.3

8 years ago

2.3.2

8 years ago

2.3.1

8 years ago

2.3.0

8 years ago

2.2.0

8 years ago

2.1.0

8 years ago

2.0.3

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.1.0

8 years ago

1.0.2

8 years ago