universal-links-handler/routes/index.js

92 lines
2.6 KiB
JavaScript
Raw Normal View History

var express = require('express');
var assetLinks = require('../resources/assetlinks.json');
2018-06-28 20:11:45 +00:00
var appleSiteAssociation = require('../resources/apple-app-site-association.json');
2018-10-05 05:31:10 +00:00
var { makeQrCodeDataUri } = require('../utils/qrcodeUtils');
var router = express.Router();
2018-07-02 18:48:58 +00:00
router.get('/', function (req, res, next) {
2018-07-02 13:07:23 +00:00
function isAndroid(userAgent) {
return userAgent.toLowerCase().indexOf("android") > -1;
}
function isIOS(userAgent) {
return userAgent.toLowerCase().indexOf("iphone") > -1;
}
if (req.query.redirect) {
2018-07-03 06:26:25 +00:00
return next();
2018-07-02 13:07:23 +00:00
}
var userAgent = req.headers['user-agent'];
2018-07-03 05:56:55 +00:00
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
res.header('Expires', '-1');
res.header('Pragma', 'no-cache');
2018-07-02 13:07:23 +00:00
if (isAndroid(userAgent)) {
2018-07-03 06:26:25 +00:00
return res.redirect("https://play.google.com/store/apps/details?id=im.status.ethereum");
2018-07-02 13:07:23 +00:00
} else if (isIOS(userAgent)) {
return res.redirect("https://testflight.apple.com/join/J8EuJmey");
2018-07-02 13:07:23 +00:00
}
2018-07-03 06:26:25 +00:00
return res.redirect("https://status.im");
});
2018-07-02 13:07:23 +00:00
2018-06-28 11:15:04 +00:00
router.get('/health', function(req, res) {
res.send('OK');
});
router.get('/.well-known/assetlinks.json', function(req, res) {
res.json(assetLinks);
});
2018-06-28 20:11:45 +00:00
router.get('/.well-known/apple-app-site-association', function(req, res) {
res.json(appleSiteAssociation);
});
2018-07-02 18:48:58 +00:00
router.get('/chat/:chatType/:chatId', function(req, res, next) {
2018-07-03 06:26:25 +00:00
const { chatId, chatType } = req.params;
res.render('index', {
2018-07-03 06:26:25 +00:00
title: `Join the ${chatType} chat: #${chatId} in Status`,
path: req.originalUrl,
id: `${chatId}`
});
});
2018-07-02 18:48:58 +00:00
router.get('/user/:userId', function(req, res, next) {
2018-10-05 05:31:10 +00:00
const { userId } = req.params;
const options = {
title: `View user ${userId} profile in Status`,
path: req.originalUrl,
id: `${userId}`
2018-10-05 05:31:10 +00:00
};
makeQrCodeDataUri(userId).then(
qrCodeDataUri => res.render('index', { ...options, qrCodeDataUri }),
error => res.render('index', options)
);
2018-06-28 07:27:15 +00:00
});
router.get('/extension/:extensionEndpoint', function(req, res, next) {
const { extensionEndpoint } = req.params;
const options = {
title: `Open extension ${extensionEndpoint} in Status`,
path: req.originalUrl,
id: `${extensionEndpoint}`
};
makeQrCodeDataUri('https://get.status.im/extension/' + extensionEndpoint).then(
qrCodeDataUri => res.render('index', { ...options, qrCodeDataUri }),
error => res.render('index', options)
);
});
2018-07-05 09:28:59 +00:00
router.get('/browse/:url(*)', function(req, res, next) {
2018-06-28 07:27:15 +00:00
res.render('index', {
2018-07-03 06:26:25 +00:00
title: `Browse to ${req.params.url} in Status`,
path: req.originalUrl,
id: `${req.params.url}`
});
});
module.exports = router;