Git Product home page Git Product logo

Comments (8)

nlf avatar nlf commented on May 22, 2024

Fixed and deployed, sorry about that!

from hapijs.com.

hickeyadamc avatar hickeyadamc commented on May 22, 2024

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.

nlf avatar nlf commented on May 22, 2024

I'll check it out and see what's going on, sorry for the premature close.

from hapijs.com.

hickeyadamc avatar hickeyadamc commented on May 22, 2024

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.

nlf avatar nlf commented on May 22, 2024

Updated the tutorial again, this time fixed for real :)

from hapijs.com.

hickeyadamc avatar hickeyadamc commented on May 22, 2024

Thanks! :)

from hapijs.com.

 avatar commented on May 22, 2024

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.

biswarupchakravarty avatar biswarupchakravarty commented on May 22, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.