Saturday 18 March 2017

http-proxy-middleware: unable to redirect localhost:9000 to localhost:8888 from nodejs to JettY

I have a Node.js (AngularJS app) application which is hosted at localhost:9000. The another part (legacy one - GWT superdev mode - JeTTy) is hosted at localhost:8888.

I would like to configure the http-proxy-middleware such that anything coming in localhost:9000 (NodeJS) should be redirected to localhost:8888 (JeTTy) with the following specifications: (There are 3 endpoints of the application):

https://localhost:9000/product ->  http://127.0.0.1:8888/product
https://localhost:9000/servlets/my_servlet1 -> http://127.0.0.1:8888/servlets/my_servlet1
https://localhost:9000/admin  -> http://127.0.0.1:8888/admin

The http-proxy-middleware setting is as follows:


     var proxy = proxyMiddleware(['/product', '/admin', '/servlets'], {
         target: 'http://127.0.0.1:8888',
         changeOrigin: true,
         xfwd: true
     });
    var app = connect();
    app.use(proxy);

The proxy is up as follows:

## node scripts/serve.js                                                                                                                                                                
[HPM] Proxy created: [ '/product, '/admin', '/servlets' ]  ->  http://127.0.0.1:8888    
listening on port 9000                                                                     
  https://localhost:9000    

Now I am trying to access (through localhost:9000) the endpoints, failed with http:500 error:

Request URL:https://localhost:9000/servlets/my_servlet1
Request Method:POST
Status Code:500 protocol = https host = null
Remote Address:[::1]:9000 


HTTP ERROR 500
Problem accessing /servlets/my_servlet1. Reason:
protocol = https host = null
Powered by Jetty://

What I am missing here?

Thanks in advanced,
Pradip



via Pradip

No comments:

Post a Comment