Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Wraps nano's API as hapi server methods and seamlessly authenticates with cookie
hapi plugin that registers server methods using nano and extends it by taking care of cookie authentication
hapi-relax enhances your hapi server by an interface for a specified CouchDB database.
If you're using cookie authentication on top of basic-auth you can also pass a username and password. Just relax and stop worrying about authentication because the plugin will check if you are authorized. If not it will use nano's auth method to get a cookie and use that in a further request. But you won't notice because that all happens internally.
It will also update its cookie when CouchDB sends a new cookie in the headers.
var Hapi = require('hapi');
var server = new Hapi.Server();
var options = { nano: { db: 'testDb' } };
server.connection({ port: 80 });
server.register({ register: require('hapi-relax'), options }, function(err) {
});
server.start();
The plugin takes the following options:
nano
- optional config object which nano will be initialized with.db
is required. Defaults to { url: 'http://localhost:5984' }
user
- optional database usernamepassword
- optional password for your database user; required if user is passedprefix
- optional namespace in which the server methods will be registered;nano
nano's API remains unchanged
var Hapi = require('hapi');
var server = new Hapi.Server();
server.connection({ port: 8080 });
var plugins = [{
register: require('hapi-relax'),
options: {
nano: {
url: 'http://localhost:5984',
db: 'db1'
},
user: 'root',
password: 'secret'
}
},
{
register: require('hapi-relax'),
options: {
nano: {
url: 'http://localhost:5984',
db: 'db2'
},
user: 'alice',
password: 'rabbit',
prefix: 'db2'
}
}];
server.register(plugins, function (err) {
if (err) {
throw err;
}
});
server.route({
method: 'GET',
path: '/db1/{key}',
handler: function (request, reply) {
var key = encodeURIComponent(request.params.key);
server.methods.nano.get(key, function (err, body, headers) {
if (err && err.reason === 'missing') {
reply('Document does not exist').code(404);
}
else {
reply(body);
}
});
}
});
server.route({
method: 'GET',
path: '/db2/{key}',
handler: function (request, reply) {
var key = encodeURIComponent(request.params.key);
server.methods.db2.get(key, function (err, body, headers) {
if (err && err.reason === 'missing') {
reply('Document does not exist').code(404);
}
else {
reply(body);
}
});
}
});
server.start(function () {
console.log('Server running at:', server.info.uri);
});
FAQs
Wraps nano's API as hapi server methods and seamlessly authenticates with cookie
We found that hapi-relax demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.