Monday, 15 May 2017

hapijs route endpoint issue with reverse proxy apache

I have created compute engine instance on Google cloud platform and installed CentOS 7, apache and nodejs. I have setup reverse proxy on server so that whenever http://[external_ip] or domain_name/api/ hit in browser it will hit nodejs server. Below is my reverse proxy configuration

/etc/httpd/conf.d/default-site.com

 ProxyPreserveHost On
 ProxyPass /api/ http://127.0.0.1:8080/
 ProxyPassReverse /api/ http://127.0.0.1:8080/

Above configuration is working fine. Below is my directory structure:

var/www/html/domain_name/public_html/index.html --> when we hit domain name directly on browser it will execute this file

var/www/html/domain_name/public/html/api/ --> Here is my nodejs application

I have installed hapi js framework. I have created following server.js file under /api/ directory.

'use strict';

 const Hapi = require('hapi');

 // Create a server with a host and port
 const server = new Hapi.Server();
 server.connection({ 
    host: '127.0.0.1', 
    port: 8080
 });

server.route({
    method: 'GET',
    path:'/', 
    handler: function (request, reply) {    
        return reply('hello world');
    }
});

 // Add the route
server.route({
    method: 'GET',
    path:'/hello', 
    handler: function (request, reply) {    
        return reply('hello world');
    }
});

// Start the server
server.start((err) => {

    if (err) {
        throw err;
    }
    console.log('Server running at:', server.info.uri);
});

I have created below two endpoints: 1. / (This route is working when I visit http:///api/ 2. /hello (This route is not working when I visit http:///api/hello/

Is there anyother configuration required when we use reverse proxy with apache and nodejs?



via Satish Sojitra

No comments:

Post a Comment