universal-links-handler/routes/index.js

69 lines
1.8 KiB
JavaScript
Raw Normal View History

var express = require('express');
var router = express.Router();
var assetLinks = require('../resources/assetlinks.json');
2018-06-28 20:11:45 +00:00
var appleSiteAssociation = require('../resources/apple-app-site-association.json');
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)) {
2018-07-03 06:26:25 +00:00
return res.redirect("https://status.im/success");
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
});
});
2018-07-02 18:48:58 +00:00
router.get('/user/:userId', function(req, res, next) {
res.render('index', {
2018-07-03 06:26:25 +00:00
title: `View user ${req.params.userId}'s profile in Status`,
2018-06-28 07:27:15 +00:00
path: req.originalUrl
});
});
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
});
});
module.exports = router;