Answer the question
In order to leave comments, you need to log in
How to put routes into separate files and include them?
Good time of the day, I’m learning hapi.js and I couldn’t master the transfer of route into separate files and connect them, more precisely 1 route could take out and connect and the rest are not given :( Please tell me how to implement it correctly
Answer the question
In order to leave comments, you need to log in
Create separate files in the folder routes/route1.js, routes/route2.js and so on and export their modules.
// routes/route1.js
module.exports = [
{
method: 'GET', path: '/routes1',
handler: function () {} },
{
method: 'GET', path: '/routes1/{id}',
handler: function () {} }
];
// /routes/index.js
var route1 = require('./route1');
var route2 = require('./route2');
var route3 = require('./route3');
var routeN = require('./routeN');
module.exports = [].concat(route1, route2, route3, routeN);
// /server.js
var routes = require('./routes');
server.route(routes);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question