0

I have deploy my angular and node project on same hosting server. my angular project url is like http://mysitedomain.com/myangularapp and my node is running on http://105.22.90.6:61001.
I am redirecting all api url like http://mysitedomain.com/api to http://105.22.90.6:61001/
I have written .htaccess as follow

RewriteEngine On
RewriteBase /
RewriteRule ^api$ http://105.22.90.6:61001/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api/(.*)$ http://103.21.90.6:61000/$1 [P,L]  

When i hit url http://mysitedomain.com/api it works fine, means it redirect to node server.
But when i hit url http://mysitedomain.com/api/login, it gives error Cannot GET /login.
i think i am missing something in last line of above code. I have tired different things but they are not working.
Can anybody give me solution on this.
This is my main server file

const express = require('express');
const http = require('http');
const cors = require('cors');
const hostname = '105.22.90.6:61001';
const port = 61001;
const api = require('./routes/api');
const app = express();  
app.use('/api',api);  
app.use(cors(corsOptions));  
app.get('/', function(req, res){
/*console.dir(req.hostname);
console.dir(req.ip);*/
res.send('Hello Admin API');
});  
app.listen(port,hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});   

And this is my api file

const express = require('express');
const router = express.Router();
const mysql = require('mysql');
router.get('/', (req, res) => {
console.log('yeah its working');
res.send('From Api route');
});
router.get('/login', (req, res) => {
res.send('In Login API');return false;
});
/*End API */
module.exports = router;`
sangRam
  • 315
  • 4
  • 17
  • Do you already run your node app? (use pm2 for it or similar) If yes, do you have the option to use nginx (wich I think is a better suited for node apps reverse proxying) – J Rui Pinto Jul 06 '19 at 07:43
  • @JRuiPinto node app is running. please check my question i have edited. – sangRam Jul 06 '19 at 08:06
  • Sounds like that error message does actually come from the nodejs server which would mean that the apache http server setup is correct. – arkascha Jul 06 '19 at 09:07
  • @arkascha my nodejs server is running. when i visit url **http://mysitedomain.com/api** it works fine. Can you tell where i am going wrong. – sangRam Jul 06 '19 at 09:29
  • No one doubted that. The question is what you get back from `http://103.21.90.6:61000/login` ... – arkascha Jul 06 '19 at 09:32

2 Answers2

2

After lots of using different solution i have got working solution.
I have made following changes in my .htaccess file.
from

RewriteRule ^api(.*)$ http://105.22.90.6:61001/$1 [P,L]

to

RewriteRule ^api(.*)$ http://105.22.90.6:61001/api/$1 [P,L]

i have just added /api in url

sangRam
  • 315
  • 4
  • 17
0

as I understand your problem, you want to deploy an Angular application in Apache, but Nodejs used with Express or other for a web server. After, if you want to know how to deploy an Angular application in Apache here or here

Nirina-aj
  • 192
  • 1
  • 3
  • 18
  • I don't have problem while running angular application on same hosting server. angular app is running fine. But i am facing issue to redirect url to node routes api. – sangRam Jul 06 '19 at 08:23