Skip to content

Commit

Permalink
feat: Render static info page for unsupported browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
kriscooke committed Oct 2, 2020
1 parent 4d4ef68 commit f60e055
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/data/unsupported-browsers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Documented in [README](../README.md#supported-browsers)

module.exports = {
ie: '<=11',
safari: '<10',
firefox: '<61',
samsung_internet: '<5',
chrome: '<68'
};
11 changes: 11 additions & 0 deletions app/server/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const express = require('express');
const http = require('http');
const https = require('https');
const Bowser = require('bowser');
const morgan = require('morgan');
const fs = require('fs');
const {postgraphile, makePluginHook} = require('postgraphile');
Expand All @@ -27,6 +28,7 @@ const {
getAllGroups,
getPriorityGroup
} = require('../lib/user-groups');
const UNSUPPORTED_BROWSERS = require('../data/unsupported-browsers');
const {run} = require('graphile-worker');
const path = require('path');
const namespaceMap = require('../data/kc-namespace-map');
Expand Down Expand Up @@ -180,6 +182,15 @@ app.prepare().then(() => {
next();
});

// Renders a static info page on unsupported browsers.
// Files in /static/ are excluded.
server.use(/^(?!\/static\/.+$).*/gi, (req, res, next) => {
const browser = Bowser.getParser(req.get('User-Agent'));
const isUnsupported = browser.satisfies(UNSUPPORTED_BROWSERS);
if (isUnsupported) res.redirect('/static/update-browser.html');
else next();
});

const store = new PgSession({
pool: pgPool,
schemaName: 'ggircs_portal_private',
Expand Down
8 changes: 8 additions & 0 deletions app/static/update-browser.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head></head>
<body>
<h1>Update your browser</h1>
<p>Here is some information</p>
</body>
</html>

0 comments on commit f60e055

Please sign in to comment.