/webpack-router

🎒⑃ Rill middleware for automatic routing using Webpack require contexts.

Primary LanguageJavaScript

Rill
@rill/webpack-router
API stability Standard NPM version Downloads Gitter Chat

A tool to automatically build a middleware for Rill based on a webpack require.context. Automatically routes all files required.

Installation

npm install @rill/webpack-router

Example App

const app = require('rill')()
const router = require('@rill/webpack-router')

// Setup all of your custom middleware (automatically routed based on file system path.)
app.use(router(require.context('./controllers', true, /\.js$/)))

Example Middleware

exports.get = ({ res }) => {
  // Export the methods you wish to handle (in this case a get request).
  res.body = 'hello world'
}

exports.post = ({ res }) => {
  // Handle other methods as well.
}

Contributions

  • Use npm test to run tests.

Please feel free to create a PR!