Last active
January 17, 2024 08:48
-
-
Save niksmac/5ec75829e9359475cbda to your computer and use it in GitHub Desktop.
Nodejs Express code to redirect mobile user agets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'), | |
app = express(); | |
app.listen(80); | |
app.get('/', function(req, res){ | |
var ua = req.header('user-agent'); | |
// Check the user-agent string to identyfy the device. | |
if(/mobile|iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile|ipad|android|android 3.0|xoom|sch-i800|playbook|tablet|kindle/i.test(ua)) { | |
res.sendfile(__dirname + '/mobile.html'); | |
} else { | |
res.sendfile(__dirname + '/index.html'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment