Skip to content

Instantly share code, notes, and snippets.

@dBitech
Last active June 5, 2018 20:47
Show Gist options
  • Save dBitech/29baa70e8abdcc3883e5de3a1deeb44f to your computer and use it in GitHub Desktop.
Save dBitech/29baa70e8abdcc3883e5de3a1deeb44f to your computer and use it in GitHub Desktop.
package.json
{
"dependencies": {
"hapi": "^17.5.1",
"hapi-router": "^4.0.0",
"path": "^0.12.7"
}
}
----8<----
index.js
const Hapi = require('hapi');
const Path = require('path');
const server = Hapi.Server({
host: 'quad',
port: 8899,
debug: { request: ['*'] },
});
const testRoutePath = Path.join(__dirname, 'test/*.js');
const init = async () => {
await server.register({
plugin: require('hapi-router'), options: {
routes: testRoutePath,
},
});
await server.start();
console.log('Server running at:', server.info.uri);
};
process.on('unhandledRejection', (err) => {
console.log(err);
process.exit(1);
});
init();
---8<----
test/example.js
module.exports = [
{
path: '/test1',
method: 'GET',
handler: function (request, reply) {
reply('hello 1');
}
},
{
path: '/test2',
method: 'GET',
handler: function (request, reply) {
reply('hello 2');
}
}
]
@dBitech
Copy link
Author

dBitech commented Jun 5, 2018

results in the following "errors"

{ Error: Cannot find module '/usr/home/darcy/min//usr/home/darcy/min/test/example.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
at Function.Module._load (internal/modules/cjs/loader.js:520:25)
at Module.require (internal/modules/cjs/loader.js:650:17)
at require (internal/modules/cjs/helpers.js:20:18)
at /usr/home/darcy/min/node_modules/hapi-router/lib/index.js:19:21
at Array.forEach ()
at /usr/home/darcy/min/node_modules/hapi-router/lib/index.js:18:13
at Array.forEach ()
at Object.register (/usr/home/darcy/min/node_modules/hapi-router/lib/index.js:15:31)
at internals.Server.register (/usr/home/darcy/min/node_modules/hapi/lib/server.js:434:35) code: 'MODULE_NOT_FOUND' }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment