npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hapi-glob-routes

v0.0.1

Published

Hapi Plugin to automatically add routes based on a filesystem glob.

Downloads

5

Readme

Hapi Glob Routes

Hapi Plugin to automatically add routes based on a filesystem glob.

Usage

Register the plugin with the server as follows:

server.register({
    register: require('hapi-glob-routes'),
    options: {
        files: path.join(__dirname, '/routes/**/*.route.js')
    }
}, function(err) {
});

This will then find every module that matches the provided filesystem glob, and treat any exports from those modules with a name of "routes" as a route definition to be passed to "server.route". For example, the following file:

import Joi from 'joi';

export const routes = {
    method: 'GET',
    path: '/api/debug/ping',
    config: {
        id: 'ping',
        tags: ['api', 'debug'],
        description: 'Debug handler to get a response back from the server',
        response: {
            schema: Joi.object({
                ping: Joi.string().description('Always the value "Pong"').example('Pong').required()
            }).description('The Ping response').required()
        },
        handler: function(request, reply) {
            const result = {
                ping: 'Pong'
            };
            return reply(result);
        }
    }
};

is a module that exposes a value called "routes". This then gets picked up and passed to server.route() by the hapi-glob-routes module automatically.

Note that because this passes through to server.route(), the exported value can be anything acceptable to that function. This means that a single module can expose multiple routes simply by exporting an array instead of a single definition.

Also note that even though the above example module is in ES6, there is no requirement for that. As long as the module has an exported value with the name "routes" that can be passed to server.route() then it doesn't matter what Javascript dialect it is written in.