
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
@magneds/hapi-server
Advanced tools
A configurable webserver package for easy bootstrapping a full blown webserver, microservice or anything in between.
The HapiServer package is a scoped packages, which means you'll have to include the scope during installation.
$ npm install --save @magneds/hapi-server
As with the installation, the scope is required to use the package as well.
const HapiServer = require('@magneds/hapi-server');
new HapiServer()
// configure the server (call as many times as needed, existing value will
// be overwritten)
.configure(/* hapi server configuration option(s) */)
// add plugins (provide plugin objects, or arrays of them, call as often
// as needed)
.plugin(/* any plugin */)
// add routes (provide route objects, or arrays of them, call as often
// as needed)
.route(/* any route */)
// start the server
.start()
// do something relevant once started (or catch errors)
.then((server) => {
console.log(`Server running at: ${server.info.uri}`);
});
HapiServer allows for a mixture of methods, whatever floats your boat, the only real requirement is to add at least the configuration of host
and port
(and even that is - as per Hapi - not mandatory, it just makes predicting the host and port more consistent) and as final call the start
method.
configure(...<object)
Set server configuration options. This method can be called multiple times, where it will overwrite any existing configuration option.
const HapiServer = require('@magneds/hapi-server');
new HapiServer()
.configure({ host: 'localhost', port: 30080 })
.configure({ port: 3000 }) // override the port to be 3000
//...
.start();
plugin(<object>|[<object>])
Register one or more Hapi compatible plugins. It allows for both objects and arrays, both also in a variadic (spread, splat, ...
) way.
Any mix of the following calls will have the same result:
plugin(PluginOne, PluginTwo)
plugin([PluginOne, PluginTwo])
plugin(...[PluginOne, PluginTwo])
const HapiServer = require('@magneds/hapi-server');
const MyFirstPlugin = require('@my/first-plugin');
const MySecondPlugin = require('@my/second-plugin');
const MyThirdPlugin = require('@my/third-plugin');
const MyFourthPlugin = require('@my/fourth-plugin');
new HapiServer()
.configure({ host: 'localhost', port: 3000 })
.plugin(MyFirstPlugin)
.plugin(MySecondPlugin)
.plugin(MyThirdPlugin)
.plugin(MyFourthPlugin)
//...
.start();
route(<object>|[<object>])
Register one or more Hapi compatible routes. It allows for both objects and arrays, both also in a variadic (spread, splat, ...
) way.
Any mix of the following calls will have the same result:
route({ method: 'GET', path: '/one', handler(request, h) { return h.response('one'); }}, ...)
route([{ method: 'GET', path: '/one', handler(request, h) { return h.response('one'); }}, ...])
const HapiServer = require('@magneds/hapi-server');
new HapiServer()
.configure({ host: 'localhost', port: 3000 })
.route({
method: 'GET',
path: '/one',
handler(request, h) {
return h.response('one');
}
})
.route([
{
method: 'GET',
path: '/two',
handler(request, h) {
return h.response('two');
}
},
{
method: 'GET',
path: '/three',
handler(request, h) {
return h.response('three');
}
}
])
.route(
{
method: 'GET',
path: '/four',
handler(request, h) {
return h.response('four');
}
},
{
method: 'GET',
path: '/five',
handler(request, h) {
return h.response('five');
}
}
)
//...
.start();
start()
As the name indicates, this will start the server. All of the configuration options, plugins and routes are prepared at this point and the Hapi server is started and provided in the Promise resolve.
const HapiServer = require('@magneds/hapi-server');
new HapiServer()
//...
.start()
.then((server) => {
console.log(`Server running at: ${server.info.uri}`);
})
.catch((error) => {
console.error(error);
});
Please see Changelog
$ npm test
Please see Contributing
The MIT License (MIT). Please see License File for more information.
FAQs
Hapi based webserver
The npm package @magneds/hapi-server receives a total of 0 weekly downloads. As such, @magneds/hapi-server popularity was classified as not popular.
We found that @magneds/hapi-server demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.