drop.chapril.org-firefoxsend/app/routes/index.js

68 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-02-08 03:52:41 +01:00
try {
// It's kind of silly that this needs to be here...
// 'nanotiming' reads this *on initialization* so
// the only way to make sure it's disabled from the
// first page load is to set it before we even
// require('choo')
localStorage.setItem('DISABLE_NANOTIMING', true);
} catch (e) {
// localStorage is disabled. nanotiming will also be
}
const choo = require('choo');
const html = require('choo/html');
const download = require('./download');
const header = require('../templates/header');
const footer = require('../templates/footer');
const fxPromo = require('../templates/fxPromo');
const app = choo();
2018-01-24 19:23:13 +01:00
function banner(state, emit) {
if (state.promo && !state.route.startsWith('/unsupported/')) {
return fxPromo(state, emit);
}
}
function body(template) {
return function(state, emit) {
const b = html`<body>
2018-01-24 19:23:13 +01:00
${banner(state, emit)}
${header(state)}
2018-02-20 08:10:03 +01:00
<main class="main">
<noscript>
2018-02-20 08:10:03 +01:00
<div class="noscript">
<h2>${state.translate('javascriptRequired')}</h2>
<p>
<a class="link" href="https://github.com/mozilla/send/blob/master/docs/faq.md#why-does-firefox-send-require-javascript">
${state.translate('whyJavascript')}
</a>
</p>
<p>${state.translate('enableJavascript')}</p>
</div>
</noscript>
${template(state, emit)}
2018-02-20 08:10:03 +01:00
</main>
${footer(state)}
</body>`;
if (state.layout) {
2018-01-24 19:23:13 +01:00
// server side only
return state.layout(state, b);
}
return b;
};
}
app.route('/', body(require('./home')));
2018-01-30 21:15:09 +01:00
app.route('/share/:id', body(require('../pages/share')));
app.route('/download/:id', body(download));
app.route('/download/:id/:key', body(download));
2018-01-30 21:15:09 +01:00
app.route('/completed', body(require('../pages/completed')));
app.route('/unsupported/:reason', body(require('../pages/unsupported')));
app.route('/legal', body(require('../pages/legal')));
app.route('/error', body(require('../pages/error')));
app.route('/blank', body(require('../pages/blank')));
app.route('*', body(require('../pages/notFound')));
module.exports = app;