index.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. const choo = require('choo');
  2. const html = require('choo/html');
  3. const nanotiming = require('nanotiming');
  4. const download = require('./download');
  5. const footer = require('../templates/footer');
  6. const fxPromo = require('../templates/fxPromo');
  7. const signupPromo = require('../templates/signupPromo');
  8. const activeBackground = require('../templates/activeBackground');
  9. const fileList = require('../templates/fileList');
  10. const profile = require('../templates/userAccount');
  11. nanotiming.disabled = true;
  12. const app = choo();
  13. function banner(state, emit) {
  14. if (state.promo && !state.route.startsWith('/unsupported/')) {
  15. return fxPromo(state, emit);
  16. }
  17. }
  18. function body(template) {
  19. return function(state, emit) {
  20. const b = html`<body class="background ${activeBackground(state)}">
  21. ${banner(state, emit)}
  22. <main class="main">
  23. <noscript>
  24. <div class="noscript">
  25. <h2>${state.translate('javascriptRequired')}</h2>
  26. <p>
  27. <a class="link" href="https://github.com/mozilla/send/blob/master/docs/faq.md#why-does-firefox-send-require-javascript">
  28. ${state.translate('whyJavascript')}
  29. </a>
  30. </p>
  31. <p>${state.translate('enableJavascript')}</p>
  32. </div>
  33. </noscript>
  34. ${signupPromo(state)}
  35. <div class="stripedBox">
  36. <div class="mainContent">
  37. ${profile(state, emit)}
  38. ${template(state, emit)}
  39. </div>
  40. </div>
  41. <div class="spacer"></div>
  42. <div class="uploads">
  43. ${fileList(state)}
  44. </div>
  45. </main>
  46. ${footer(state)}
  47. </body>`;
  48. if (state.layout) {
  49. // server side only
  50. return state.layout(state, b);
  51. }
  52. return b;
  53. };
  54. }
  55. app.route('/', body(require('../pages/welcome')));
  56. app.route('/share/:id', body(require('../pages/share')));
  57. app.route('/download/:id', body(download));
  58. app.route('/download/:id/:key', body(download));
  59. app.route('/unsupported/:reason', body(require('../pages/unsupported')));
  60. app.route('/legal', body(require('../pages/legal')));
  61. app.route('/error', body(require('../pages/error')));
  62. app.route('/blank', body(require('../pages/blank')));
  63. app.route('/signin', body(require('../pages/signin')));
  64. app.route('/api/fxa/oauth', async function(state, emit) {
  65. try {
  66. await state.user.finishLogin(state.query.code);
  67. emit('replaceState', '/');
  68. } catch (e) {
  69. emit('replaceState', '/error');
  70. setTimeout(() => emit('render'));
  71. }
  72. });
  73. app.route('*', body(require('../pages/notFound')));
  74. module.exports = app;