prod.js 845 B

1234567891011121314151617181920212223242526272829303132
  1. const express = require('express');
  2. const path = require('path');
  3. const Sentry = require('@sentry/node');
  4. const config = require('../config');
  5. const routes = require('../routes');
  6. const pages = require('../routes/pages');
  7. const expressWs = require('@dannycoates/express-ws');
  8. if (config.sentry_dsn) {
  9. Sentry.init({ dsn: config.sentry_dsn });
  10. }
  11. const app = express();
  12. expressWs(app, null, { perMessageDeflate: false });
  13. routes(app);
  14. app.ws('/api/ws', require('../routes/ws'));
  15. app.use(
  16. express.static(path.resolve(__dirname, '../../dist/'), {
  17. setHeaders: function(res, path) {
  18. if (!/serviceWorker\.js$/.test(path)) {
  19. res.set('Cache-Control', 'public, max-age=31536000, immutable');
  20. }
  21. res.removeHeader('Pragma');
  22. }
  23. })
  24. );
  25. app.use(pages.notfound);
  26. app.listen(config.listen_port, config.listen_address);