M
M
Maxim2015-10-28 19:54:16
Node.js
Maxim, 2015-10-28 19:54:16

How to redirect all nodejs\express requests?

Tell me how to redirect all requests to another domain with all params and query? I use expressjs on the server.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Olya Pilipenko, 2015-10-30
@pilipolya

Install the request module for http requests. And for example, it would be possible to make middleware for all requests.

var app = express();
var request = require('request');
app.use(function (req, res, next) {

  request('http://www.google.com', function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body) // Show the HTML for the Google homepage.
  }

});
  next();
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question