
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
hapi-route-hierarchy
Advanced tools
Hapi plugin that automatically sets up your routes based on your directory hierarchy.
Hapi plugin that automatically sets up your routes based on your directory hierarchy.
The purpose of this plugin is to allow intuitive route setup by basing routes on your directory structure. For example, imagine you have a Hapi project with this folder structure:
my_hapi_project
│ server.js
│
└───routes
│ login.js
│
└───users
│ group_a.js
│ group_b.js
Assume that server.js
simply starts the Hapi server, after registering the plugin like this:
server.register(
{
plugin: require( 'hapi-route-hierarchy' ),
options: {
root: __dirname + '/routes',
glob_pattern: '**/*.js'
}
}, ( err ) => {
// Start the server...
}
)
All the files under /routes
include the data for all the routes. So for example, /routes/login.js
might look like this:
module.exports = {
method: 'GET',
path: '/login',
handler: function( request, h ) {
return h.response( 'You have been authenticated!' );
}
};
This will result in a route at /login
, which is rather boring, but what if we put something similar in /routes/users/group_a.js
:
module.exports = {
method: 'GET',
path: '/group_a',
handler: function( request, h ) {
return h.response( 'Here is a list of all users in group A!' );
}
};
This would result in a route at /users/group_a
.
In this way you can easily keep your routes organized by ensuring they always match your directory structure.
REQUIRED
Type: string
Description: The directory to search for files with route data. This can accept 2 types of paths:
process.cwd()
string
object
glob
NPM module. Here is a full list of available options.The route files can define route data in 3 different ways:
module.exports = {
method: 'GET',
path: '/some_path',
handler: function( request, h ) {
// Do something...
}
};
module.exports = [
{
method: 'GET',
path: '/some_path',
handler: function( request, h ) {
// Do something...
}
},
{
method: 'POST',
path: '/some_other_path',
handler: function( request, h ) {
// Do something...
}
}
];
Note that this variation allows you to access the Hapi server object
module.exports = function( server ){
return {
method: 'GET',
path: '/some_path',
handler: function( request, h ) {
let some_fancy_plugin = request.server.plugins['some_fancy_plugin'];
h.response( some_fancy_plugin.doFancyThings() );
}
};
};
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.
FAQs
Hapi plugin that automatically sets up your routes based on your directory hierarchy.
The npm package hapi-route-hierarchy receives a total of 1 weekly downloads. As such, hapi-route-hierarchy popularity was classified as not popular.
We found that hapi-route-hierarchy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.