Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. // @ts-nocheck
  2. // TODO: remove once there are typings in place
  3.  
  4. import './css/tailwind.css';
  5. import * as sapper from '@sapper/server';
  6. import compression from 'compression';
  7. import express from 'express';
  8. import helmet from "helmet";
  9. import sirv from 'sirv';
  10. import uuidv4 from 'uuid/v4';
  11.  
  12. const {
  13. PORT,
  14. NODE_ENV
  15. } = process.env;
  16. const dev = NODE_ENV === 'development';
  17.  
  18. const app = express();
  19.  
  20.  
  21. if ( dev ) app.use( sirv( 'static', { dev } ) );
  22.  
  23. app.use( ( request, response, next ) => {
  24. response.locals.nonce = uuidv4();
  25. next();
  26. } );
  27.  
  28. app.use(
  29. helmet(
  30. // {
  31. // contentSecurityPolicy: {
  32. // directives: {
  33. // scriptSrc: [
  34. // "'self'",
  35. // ( request, response ) => `'nonce-${response.locals.nonce}'`
  36. // ]
  37. // },
  38. // browserSniff: false
  39. // }
  40. // }
  41. ),
  42. sapper.middleware(),
  43. compression({ threshold: 0 })
  44. );
  45.  
  46. if ( dev ) {
  47. // only listen when started in dev
  48. app.listen( PORT, err => {
  49. if ( err ) console.log( 'error', err );
  50. } );
  51. }
  52.  
  53. export {
  54. app
  55. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement