0

I am trying to deploy a node app from a local to production environment.

On my local environment my code looked likes the code below and all works perfectly. Navigate to localhost:3000, click login, and you are brought to the login route.

LOCAL app.js file

var express = require('express');
var bodyParser = require("body-parser");

var app = express();

app.use(express.static(__dirname + '/public'))
  .use(bodyParser());

app.get('/login', function(req, res) {
  res.send('log me in!');
});

console.log('Listening on 3000');
app.listen(3000);

I have then uploaded to a server and am running the app.js file using forever - i.e. forever start app.js. I can navigate to the homepage which is the index.html file in the public folder. The url looks like this - http://162.xx.xxx.xxx/project/public/

My app.js file looks the same as above apart from this line:

app.get('http://162.xx.xxx.xxx/project/public/login', function(req, res) {
  res.send('log me in!');
});

when i try and navigate to the login url it says:

The requested URL /project/login was not found on this server. Apache Server at http://162..*.*** Port 80

Can anyone advise what I am doing wrong?

  • Do you really want to put your server IP address in the route? – Ahsan Dec 02 '16 at 15:23
  • originally i tried without it, and used the same code as my local code but that didn't work. Do you think it should work if I just used `/login`? –  Dec 02 '16 at 15:24
  • It should only be /login. Your Apache should be proxy passing to `localhost:3000` – Ahsan Dec 02 '16 at 15:24
  • ok, so if it is `/login/` in the `app.js` file, what should the link be on the front end? `http://162.xx.xxx.xxx/project/public/login`? –  Dec 02 '16 at 15:25

1 Answers1

0

Your apache should just be proxy passing to node:

ProxyPass / http://localhost:3000/

Leave your node to be listening to port 3000. Your do not need to modify any routes.

Then access your application from your browser like: http://xxx.xxx.xxx.xxx/login

A good read here: Apache and Node.js on the Same Server

Community
  • 1
  • 1
Ahsan
  • 3,845
  • 2
  • 36
  • 36
  • when I try and access that from my browser it says `The requested URL /login/ was not found on this server.` –  Dec 02 '16 at 15:33
  • just use `http://162.xx.xxx.xxx/login`. I am expecting your apache virtualhost is listening on port 80? Please share your apache virtualhost code if necessary. – Ahsan Dec 02 '16 at 15:33
  • this is what it says `Not Found The requested URL /login/ was not found on this server. Apache Server at xxx.xx.xxx.xxx Port 80` –  Dec 02 '16 at 15:34
  • Please share your apache virtualhost configuration. Also, is it a linux server or windows? – Ahsan Dec 02 '16 at 15:35
  • linux server. How do i find the apache virtual host configuration? –  Dec 02 '16 at 15:36
  • Usually inside `/etc/apache2/sites-enabled/` or `/etc/httpd/sites-enabled/` – Ahsan Dec 02 '16 at 15:41
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/129639/discussion-between-phantom-and-raptor). –  Dec 02 '16 at 15:42