我试图快速向客户展示基于其设备的不同网站。即移动用户可以通过移动应用和桌面用户获得网络应用。Express.compress和移动设备
这是我的代码:
var express = require('express'),
app = express();
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)) {
console.log("mobile");
app.use('/', express.static(__dirname + '/mobile-app/www'));
res.sendfile(__dirname + '/mobile-app/www/index.html');
} else {
console.log("web");
app.use('/', express.static(__dirname + '/web-app/www'));
res.sendfile(__dirname + '/web-app/www/index.html');
}
});
每个应用程序工作正常。但是,如果我使用Chrome网络工具更改设备,然后进行刷新,则不会加载其他设备。即如果第一个服务实例位于Web应用程序上,并且我在移动应用程序上刷新...移动应用程序将无法工作。如果第一个服务实例位于移动应用程序上,则刷新到Web应用程序意味着无法加载。
有没有关于如何更好地做到这一点的任何想法?
感谢