index.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. const choo = require('choo');
  2. const html = require('choo/html');
  3. const nanotiming = require('nanotiming');
  4. const download = require('./download');
  5. const header = require('../templates/header');
  6. const footer = require('../templates/footer');
  7. const fxPromo = require('../templates/fxPromo');
  8. nanotiming.disabled = true;
  9. const app = choo();
  10. function banner(state, emit) {
  11. if (state.promo && !state.route.startsWith('/unsupported/')) {
  12. return fxPromo(state, emit);
  13. }
  14. }
  15. function body(template) {
  16. return function(state, emit) {
  17. const b = html`<body>
  18. ${banner(state, emit)}
  19. ${header(state)}
  20. <main class="main">
  21. <noscript>
  22. <div class="noscript">
  23. <h2>${state.translate('javascriptRequired')}</h2>
  24. <p>
  25. <a class="link" href="https://github.com/mozilla/send/blob/master/docs/faq.md#why-does-firefox-send-require-javascript">
  26. ${state.translate('whyJavascript')}
  27. </a>
  28. </p>
  29. <p>${state.translate('enableJavascript')}</p>
  30. </div>
  31. </noscript>
  32. ${template(state, emit)}
  33. </main>
  34. ${footer(state)}
  35. </body>`;
  36. if (state.layout) {
  37. // server side only
  38. return state.layout(state, b);
  39. }
  40. return b;
  41. };
  42. }
  43. app.route('/', body(require('./home')));
  44. app.route('/share/:id', body(require('../pages/share')));
  45. app.route('/download/:id', body(download));
  46. app.route('/download/:id/:key', body(download));
  47. app.route('/completed', body(require('../pages/completed')));
  48. app.route('/unsupported/:reason', body(require('../pages/unsupported')));
  49. app.route('/legal', body(require('../pages/legal')));
  50. app.route('/error', body(require('../pages/error')));
  51. app.route('/blank', body(require('../pages/blank')));
  52. app.route('*', body(require('../pages/notFound')));
  53. module.exports = app;