I am trying to use nodejs as a layer between my public website and a server inside our network.
I use express.js to create a simple REST api. The API endpoint should initiate a request call to the webservice and return a result.
But calling the request inside my function .get()does nothing.
I want to return the result from an attached call that will be returned.
the code:
var express = require('express');
var bodyParser = require('body-parser');
var request = require('request');
var port = process.env.PORT || 8080;
var app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.get('/invoice', function(req, res){
res.send('Express is workiung on IISNode')
});
app.get('/invoice/api/costumer=:customerId&invoice=:invoiceId', function(req, res){
res.send('Customer ID: ' + req.params.customerId + ' Invoice ID: '+ req.params.invoiceId)
var url = 'http://xxx/invapp/getinvoice?company='+req.params.customerId+'S&customerno=13968&invoiceno='+req.params.invoiceId+'';
request('http://www.google.com', function (error, response, body) {
res.send(body);
})
});
app.listen(port);
console.log("API is running on port " + port);
Any suggestions?
source
share