Saturday 18 March 2017

hapijs handlebars not responding

I am trying to use a handlebars but the page is not responding when my routes are correct.

I have this in my server.js, I am not showing it all, only the important parts:

const Hapi = require('hapi');
const Good = require('good');
const Vision = require('vision');
const routes = require('./src/routes');

const server = new Hapi.Server({
connections: {
    routes: {
        files: {
            relativeTo: Path.join(__dirname, 'public')
        }
    }
}
});

server.register([{
    register: Good,
    options: {
    ...
}, {
    register: Vision,
}
], (err) => {


server.views({
    engines: {
        'html': {
            module: require('handlebars'),
        }
    },
    relativeTo: __dirname,
    path: 'templates',
});

routes(server);

server.start((err) => { ...

});

In my routes.js I have this (again only the important parts):

server.route({
    method: 'GET',
    path: '/demo',
    handler: (request, reply) => {
        reply.view('index.html');
    }
});

I get no response from the server, when I do localhost:3004/demo. The file index.html EXISTS! I am sure about that. The Chrome keeps loading and loading forever. What could be the problem? Is there any way to debug this? I get no errors. I've tried a lot of things like providing the full path instead of relativeTo and path.

What am I missing?



via durisvk10

No comments:

Post a Comment