Vladimir
Vladimir

Reputation: 1789

hapi-swaggered how to group routes and send header in each request

I am using this pkg to document my code:

https://github.com/z0mt3c/hapi-swaggered

Is it possible to send header with JWT on each request send from doc? And how can I group routes together?

Upvotes: 0

Views: 505

Answers (1)

kgangadhar
kgangadhar

Reputation: 5088

To configure your routes using hapi-swagger follow these steps:

  • Create the endpoint you want, let it be file1.js

    module.exports = function (server, options) {
        server.route({
            method: 'GET',
            path: '/your_path',
            // code goes here.................
        });
    }
    
  • Create the file to add these endpoints, let it be index.js:

    exports.register = function (server, options, next) {
        require('./libs/file1.js')(server,options);    
      next();
    };
    
  • Register this index.js file in your server in server.js:

    var index = require('index'); 
    
    server.register([{
        register: require('hapi-swagger'),
        options: {
            apiVersion: "0.0.1"
        }
    }, {
        register: index
    }]);
    

    You can maintain all your endpoints in a folder and can register all to index.js, providing correct path is enough to register endpoint urls

And to add JWT header to the Hapi-swagger, you will get details in this Github page

And can also use hapi-auth-jwt2 npm package that supports the authentication scheme/plugin for Hapi.js apps using JSON Web Tokens

Upvotes: 0

Related Questions