send/app/routes/index.js

74 lines
2.3 KiB
JavaScript
Raw Normal View History

const choo = require('choo');
const html = require('choo/html');
const nanotiming = require('nanotiming');
const download = require('./download');
const footer = require('../templates/footer');
const fxPromo = require('../templates/fxPromo');
2018-07-31 18:09:18 +00:00
const signupPromo = require('../templates/signupPromo');
2018-06-19 19:58:42 +00:00
const activeBackground = require('../templates/activeBackground');
2018-07-31 18:09:18 +00:00
const fileList = require('../templates/fileList');
const profile = require('../templates/userAccount');
nanotiming.disabled = true;
const app = choo();
2018-01-24 18:23:13 +00:00
function banner(state, emit) {
if (state.promo && !state.route.startsWith('/unsupported/')) {
return fxPromo(state, emit);
}
}
function body(template) {
return function(state, emit) {
2018-06-21 18:28:31 +00:00
const b = html`<body class="background ${activeBackground(state)}">
2018-01-24 18:23:13 +00:00
${banner(state, emit)}
2018-02-20 07:10:03 +00:00
<main class="main">
<noscript>
2018-02-20 07:10:03 +00: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>
2018-08-09 00:24:58 +00:00
${signupPromo(state)}
2018-06-20 22:23:15 +00:00
<div class="stripedBox">
<div class="mainContent">
2018-07-31 18:09:18 +00:00
${profile(state)}
2018-06-20 22:23:15 +00:00
${template(state, emit)}
</div>
</div>
2018-07-31 18:09:18 +00:00
2018-06-20 22:23:15 +00:00
<div class="spacer"></div>
2018-07-31 18:09:18 +00:00
<div class="uploads">
${fileList(state)}
</div>
2018-02-20 07:10:03 +00:00
</main>
${footer(state)}
</body>`;
if (state.layout) {
2018-01-24 18:23:13 +00:00
// server side only
return state.layout(state, b);
}
return b;
};
}
2018-08-03 19:24:41 +00:00
app.route('/', body(require('../pages/welcome')));
2018-01-30 20:15:09 +00: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 20:15:09 +00:00
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')));
2018-07-31 18:09:18 +00:00
app.route('/signin', body(require('../pages/signin')));
module.exports = app;