Comments (8)
Fixed and deployed, sorry about that!
from hapijs.com.
I am still getting this error:
/Users/adamhickey/Prototype/node_modules/hapi/node_modules/hoek/lib/index.js:663
throw new Error(msgs.join(' ') || 'Unknown error');
^
Error: Missing or undefined handler: GET /
at Object.exports.assert (/Users/adamhickey/Prototype/node_modules/hapi/node_modules/hoek/lib/index.js:663:11)
at new module.exports.internals.Route (/Users/adamhickey/Prototype/node_modules/hapi/lib/route.js:35:10)
at internals.Connection._addRoute (/Users/adamhickey/Prototype/node_modules/hapi/lib/connection.js:342:17)
at internals.Connection._route (/Users/adamhickey/Prototype/node_modules/hapi/lib/connection.js:334:18)
at internals.Plugin._apply (/Users/adamhickey/Prototype/node_modules/hapi/lib/plugin.js:432:14)
at internals.Plugin.route (/Users/adamhickey/Prototype/node_modules/hapi/lib/plugin.js:407:10)
at /Users/adamhickey/Prototype/server.js:30:12
at done (/Users/adamhickey/Prototype/node_modules/hapi/node_modules/items/lib/index.js:30:25)
at Object.exports.register (/Users/adamhickey/Prototype/node_modules/hapi-auth-basic/lib/index.js:15:5)
at /Users/adamhickey/Prototype/node_modules/hapi/lib/plugin.js:235:14
from hapijs.com.
I'll check it out and see what's going on, sorry for the premature close.
from hapijs.com.
No problem! Thanks for the fast response!
Turns out the error was caused by lack of a handler. Also, a call to start might be helpful too. Here's what worked for me:
var Bcrypt = require('bcrypt');
var Hapi = require('hapi');
var Basic = require('hapi-auth-basic');
var server = new Hapi.Server();
server.connection({ port: 3000 });
var users = {
john: {
username: 'john',
password: '$2a$10$iqJSHD.BGr0E2IxQwYgJmeP3NvhPrXAeLSaGCj6IR/XU5QtjVu5Tm', // password is: 'secret'
name: 'John Doe',
id: '2133d32a'
}
};
var validate = function (username, password, callback) {
var user = users[username];
if (!user) {
return callback(null, false);
}
Bcrypt.compare(password, user.password, function (err, isValid) {
callback(err, isValid, { id: user.id, name: user.name });
});
};
server.register(Basic, function (err) {
server.auth.strategy('simple', 'basic', { validateFunc: validate });
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
reply('Success!');
},
config: { auth: 'simple' } });
});
server.start(function () {
console.log('Server running at:', server.info.uri);
});
from hapijs.com.
Updated the tutorial again, this time fixed for real :)
from hapijs.com.
Thanks! :)
from hapijs.com.
server.register(require('inert'), (err) => {
if (err) { throw err; }
server.route({
method: 'GET',
path: '/mydemo',
handler: function (request, reply)
{
reply.file('./public/mydemo.html');
}
});
server.start((err) => {
if (err) {
throw err;
}
server.log('info', 'Server running at: ' + server.info.uri);
});
});
I am getting an error while using the inert@4 plugin in hapi@17 in the above code. Can some one please help me fix this? Following is the error I am able to see on cmd.
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): AssertionError [ERR_ASSERTION]: Invalid register options "value" must be an object
(node:14584) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
from hapijs.com.
@Npednekar9
Try switching to an async/await
structure. This is what works for me:
async function startServer() {
await server.register(require('inert'));
server.route({
method: 'GET',
path: '/mydemo',
handler: function(request, reply) {
reply.file('./public/mydemo.html');
}
});
await server.start();
});
startServer();
Check this issue for further details.
TLDR; v17 moved to an async/await approach, and away from callbacks, and the documentation is in process of being updated. Alternatively, you could downgrade to v16.
from hapijs.com.
Related Issues (20)
- Add prettier to the project HOT 7
- Add mention about github's token scope
- rename or remove host:'localhost' HOT 5
- Add mention in update page about release information
- Update slack invite link
- Remove mention of the gitter channel
- Remove Gitter/IRC mentions in GETTING_STARTED other than english HOT 7
- The "Getting started" script should follow coding conventions HOT 5
- Homepage was 500ing HOT 8
- Show api docs for v17 HOT 1
- API page display 17.8.5 twice instead of latest v17 and v16 HOT 2
- Categorize resources by hapi version
- Fix github rate limit error 500
- Remove community page HOT 2
- Side menu not displaying properly on API Page
- Bell module summary display is broken on API page HOT 1
- Mistake in route query docs HOT 1
- Update tutorials to use scoped packages HOT 2
- Current version on homepage is out of date HOT 3
- The styleguide page is broken HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hapijs.com.