Reputation: 45
I want to make my Nodejs app for different user agents(Web, iOS, Android) with different data(i.e filter field for certain user agent). Should I do different route for each or put in the same route and conditioning user agent? If I have to do in same route, which node module you recommend me?
Upvotes: 0
Views: 379
Reputation: 626
You can use the same route and useragent
package to parse the req.headers['user-agent']
(express
) variable.
Example:
const useragent = require('useragent')
// ...
const ua = useragent.is(req.headers['user-agent'])
if (ua.firefox) {
// firefox stuff
} else if (ua.chrome) {
// chrome suff
}
Upvotes: 1