Redirect server side

This commit is contained in:
Andrea Maria Piana 2018-07-02 15:07:23 +02:00
parent 861736a542
commit 227a1e8b27
2 changed files with 51 additions and 6 deletions

View File

@ -3,6 +3,35 @@ var router = express.Router();
var assetLinks = require('../resources/assetlinks.json');
var appleSiteAssociation = require('../resources/apple-app-site-association.json');
function serverSideRedirect(req, res, next) {
function isAndroid(userAgent) {
return userAgent.toLowerCase().indexOf("android") > -1;
}
function isIOS(userAgent) {
return userAgent.toLowerCase().indexOf("iphone") > -1;
}
console.log(req.query);
console.log(req.params);
console.log(req.queryParams);
if (req.query.redirect) {
return next();
}
var userAgent = req.headers['user-agent'];
if (isAndroid(userAgent)) {
return res.redirect("https://play.google.com/store/apps/details?id=im.status.ethereum");
} else if (isIOS(userAgent)) {
return res.redirect("https://status.im/success")
}
return res.redirect("https://status.im")
}
router.get('/health', function(req, res) {
res.send('OK');
});
@ -15,21 +44,21 @@ router.get('/.well-known/apple-app-site-association', function(req, res) {
res.json(appleSiteAssociation);
});
router.get('/chat/:chatType/:chatId', function(req, res, next) {
router.get('/chat/:chatType/:chatId', serverSideRedirect, function(req, res, next) {
res.render('index', {
title: 'Status.im join ' + req.params.chatId + ' chat',
path: req.originalUrl
});
});
router.get('/user/:userId', function(req, res, next) {
router.get('/user/:userId', serverSideRedirect, function(req, res, next) {
res.render('index', {
title: 'Status.im view ' + req.params.userId + ' profile',
path: req.originalUrl
});
});
router.get('/browse/:url', function(req, res, next) {
router.get('/browse/:url', serverSideRedirect, function(req, res, next) {
res.render('index', {
title: 'Status.im browse ' + req.params.url + ' dapp',
path: req.originalUrl

View File

@ -11,13 +11,29 @@ shakedown GET /.well-known/apple-app-site-association
content_type 'application/json'
contains 'im.status.ethereum'
shakedown GET /chat/public/abc
shakedown GET /chat/public/abc?redirect=0
status 200
shakedown GET /user/blah
# Android test
shakedown GET /chat/public/abc -H "User-Agent: Mozilla/5.0 (Linux; Android 7.0; SM-G892A Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/60.0.3112.107 Mobile Safari/537.36"
header_contains 'Location' 'https://play.google.com/store/apps/details?id=im.status.ethereum'
status 302
# IOS
shakedown GET /chat/public/abc -H "User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1"
header_contains 'Location' 'https://status.im/success'
status 302
# Anything else
shakedown GET /chat/public/abc -H "User-Agent: Unknown"
header_contains 'Location' 'https://status.im'
status 302
shakedown GET /user/blah?redirect=0
status 200
shakedown GET /browse/www.test.com
shakedown GET /browse/www.test.com?redirect=0
status 200
shakedown GET /health