javascript - Set user agent for Node JS server -


is possible configure user-agent of simple node js server? example, run node server using iphone user agent simulate device display. not sure if there npm package doing or custom javascript manipulate user-agent of node js server.

detail: aware express-user-agent

it give parsing feature , access current user-agent within express app.

here code of node js server:

 var express = require('express');  var app = express();  var server = require('http').createserver(app);  var io = require('socket.io')(server);  var exec = require('child_process').exec;  var shell = require('shelljs');   app.use('/public', express.static(__dirname + '/public'));   app.get('/', function(req, res,next) {   res.sendfile(__dirname + '/index.html');  });   server.listen(4200);   io.on('connection', function(client) {   client.on('join', function(data) {     console.log(data);   });   client.on('command', function(data) {   console.log(data);   });  }); 

look this:

var request = require('request');  var options = {   url: 'http://localhost:4200/test',   headers: {     'user-agent': 'my iphine 7s'   } };  function callback(error, response, body) {           //do somethings }  request(options, callback); 

for example can add test-route server , send request. dont forget url request, must http://localhost:4200/test, code:

...   app.use('/public', express.static(__dirname + '/public'));   app.get('/', function(req, res,next) {   res.sendfile(__dirname + '/index.html');  });  app.get('/test', function(req, res,next) {   console.log(req.headers); });   server.listen(4200);  ... 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -