leaonline:webapp

v1.0.0Published 4 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Meteor extended Webapp

JavaScript Style Guide Project Status: Active – The project has reached a stable, usable state and is being actively developed. GitHub file size in bytes GitHub

Extended Meteor webapp for easier creation of routes, a little bit similar to express routes.

Installation

Add this package as usual:

$ meteor add leaonline:webapp

Optional: If you want to use body-parser functionality, you also need to install this npm package:

$ meteor npm install --save body-parser

The body-parser package is not coupled as hard dependency to this package, so if you don't install it it won't be bundled.

Usage

This package extends webapp so you don't need to import this package directly. Just import WebApp and define ['get', 'head', 'post', 'put', 'delete', 'options', 'trace', 'patch'] handlers:

1import { WebApp } from 'meteor/webapp'
2
3const app = WebApp.connectHandlers
4app.defineMethod('get') // make app.get available
5app.get('/some-data', function(req, res, next) {
6  // ...
7})

You can also use these functions via WebApp.rawConnectHandlers if you need to execute them before any other middleware.

If you need to use urlEncoded or json via body-parser you need to call them before defining your routes:

1import { WebApp } from 'meteor/webapp'
2import bodyParser from 'body-parser'
3
4const app = WebApp.connectHandlers
5app.urlEncoded(bodyParser, { extended: false, limit: '100kb' })
6app.json(bodyParser, { limit: '100kb' })

Note, that body parser needs to be injected, because it is not hard-wired to the package. These functions also work on WebApp.rawConnectHandlers

Using a router

This package did not include router functionality, because there are many routers out there.

Tests

Run Meteor package tests using meteortesting:mocha via

$ TEST_WATCH=1 TEST_CLIENT=0 meteor test-packages ./ --driver-package meteortesting:mocha

License

MIT, see LICENSE