0

Following this example, I am running a node application that I copied from here:

I have set up Apache 2. for VirtualHost, and as show below, I am proxying an internet address to the local node application running locally.

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:3000/
    ProxyPassReverse / http://127.0.0.1:3000/
    ErrorLog /var/log/httpd/hellomvc-error.log
    CustomLog /var/log/httpd/hellomvc-access.log common

    LogLevel debug
    ServerSignature Off
</VirtualHost>

Using Postman, When I try to POST to the internet site like this:

http://xxx.xxx.xxx.xxx/api/auth/register/[x-www-form-url-encoded parameters here]

I get error:

Proxy Error

The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request POST /api/auth/register.

Reason: Error reading from remote server

Do I also have to do a rewrite on /api/auth/register/ and pass the parameters to it in the <VirtualHost *:80> section above? In the spirit of something like this?

RewriteEngine On
RewriteCond %{SERVER_NAME} !^www\.mydomain\.fi
RewriteRule /(.*) http://www.mydomain.fi/$1 [redirect=301L]

EDIT 1

I tried

curl -d "name=Ivan&email=idf@xxxx.com&password=secret" -X POST http://localhost:5000/api/auth/register

After a long time it comes back with:

curl: (52) Empty reply from server

Same thing with

curl -d "name=Ivan&email=idf@xxxcom&password=secret" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://localhost:5000/api/auth/register

EDIT 2

This gets a response back, albeit an error. Progress!

curl -d "name=Ivan&email=idf@xxx.com&password=secret" -H "Content-Type: application/x-www-form-url-encoded" -X POST http://localhost:5000/api/auth/register


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Error: Illegal arguments: undefined, string<br> &nbsp; &nbsp;at Error (native)<br> &nbsp; &nbsp;at Object.bcrypt.hashSync (/var/www/securing-restful-apis-with-jwt/node_modules/bcryptjs/dist/bcrypt.js:189:19)<br> &nbsp; &nbsp;at /var/www/securing-restful-apis-with-jwt/auth/AuthController.js:46:31<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/var/www/securing-restful-apis-with-jwt/node_modules/express/lib/router/layer.js:95:5)<br> &nbsp; &nbsp;at next (/var/www/securing-restful-apis-with-jwt/node_modules/express/lib/router/route.js:137:13)<br> &nbsp; &nbsp;at Route.dispatch (/var/www/securing-restful-apis-with-jwt/node_modules/express/lib/router/route.js:112:3)<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/var/www/securing-restful-apis-with-jwt/node_modules/express/lib/router/layer.js:95:5)<br> &nbsp; &nbsp;at /var/www/securing-restful-apis-with-jwt/node_modules/express/lib/router/index.js:281:22<br> &nbsp; &nbsp;at Function.process_params (/var/www/securing-restful-apis-with-jwt/node_modules/express/lib/router/index.js:335:12)<br> &nbsp; &nbsp;at next (/var/www/securing-restful-apis-with-jwt/node_modules/express/lib/router/index.js:275:10)<br> &nbsp; &nbsp;at jsonParser (/var/www/securing-restful-apis-with-jwt/node_modules/body-parser/lib/types/json.js:118:7)<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/var/www/securing-restful-apis-with-jwt/node_modules/express/lib/router/layer.js:95:5)<br> &nbsp; &nbsp;at trim_prefix (/var/www/securing-restful-apis-with-jwt/node_modules/express/lib/router/index.js:317:13)<br> &nbsp; &nbsp;at /var/www/securing-restful-apis-with-jwt/node_modules/express/lib/router/index.js:284:7<br> &nbsp; &nbsp;at Function.process_params (/var/www/securing-restful-apis-with-jwt/node_modules/express/lib/router/index.js:335:12)<br> &nbsp; &nbsp;at next (/var/www/securing-restful-apis-with-jwt/node_modules/express/lib/router/index.js:275:10)</pre>
</body>
</html>
Ivan
  • 299
  • 1
  • 4
  • 13
  • 1
    And does the POST work without the proxy? I mean directly to port 3000. No, you need no rewrites to make proxy work. – Ondřej Xicht Světlík Jan 22 '18 at 20:16
  • The problem is the server has no GUI so I cannot use Postman locally, or a browser locally to test 127.0.0.1:3000. There is probably some way to use curl/wget, but I don't know that syntax. – Ivan Jan 22 '18 at 20:31
  • I see, you can't configure the node server to run on a public IP address just for testing purposes? – Ondřej Xicht Světlík Jan 22 '18 at 20:43
  • 1
    You really should try the POST to the node application directly first, I see no problem in your Apache configuration so my guess is that your node application doesn't do what you are expecting it to do. [CURL](https://gist.github.com/subfuzion/08c5d85437d5d4f00e58) can really help you. – Ondřej Xicht Světlík Jan 22 '18 at 20:50
  • See EDIT 1. something is wrong - has nothing to do with apache. – Ivan Jan 22 '18 at 21:21
  • Just to be sure, in your Apache configuration, you use port 3000, in the curl example 5000, are you really checking the right one? – Ondřej Xicht Světlík Jan 22 '18 at 21:25
  • Also tried curl -d "name=Ivan&email=idf@xxxcom&password=secret" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://localhost:5000/api/auth/register – Ivan Jan 22 '18 at 21:26
  • Yeah I am using the right one. I just chaged it to 5000. – Ivan Jan 22 '18 at 21:27
  • See EDIT 2. Making progress. – Ivan Jan 22 '18 at 21:32
  • Well, good luck then, I don't think I can help you with that, I only understand the Apache part here :-). – Ondřej Xicht Světlík Jan 22 '18 at 21:36
  • 1
    I figured it out. Even so, the answer/link of how to use curl is worth the price of admission. Thanks! – Ivan Jan 23 '18 at 00:43

0 Answers0