Guest User

Untitled

a guest
Nov 24th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. const express = require('express');
  2. const Gun = require('gun');
  3. const join = require('path').join;
  4. const livereload = require('livereload');
  5. const PORT = process.env.PORT || 8080;
  6. const root = process.cwd();
  7. const throng = require('throng');
  8. const WORKERS = process.env.WEB_CONCURRENCY || 1;
  9.  
  10. function start() {
  11. const app = express();
  12. app.use(Gun.serve);
  13. app.use(express.static(join(root, 'public')));
  14. app.use(express.static(join(root, 'node_modules')));
  15. app.use(express.static(join(root, 'src')));
  16.  
  17. app.get('*', (req, res) => {
  18. res.sendFile(join(root, 'public', 'index.html'));
  19. });
  20.  
  21. const server = app.listen(PORT, () => console.log(`server listening on port: ${PORT}`));
  22.  
  23. Gun({
  24. web: server,
  25. localStorage: false
  26. });
  27.  
  28. if (process.NODE_ENV !== 'production') {
  29. const lrserver = livereload.createServer({
  30. exts: ['html', 'css', 'js', 'mjs'],
  31. extensions: ['html', 'css', 'js', 'mjs']
  32. }, () => {
  33. console.log(`livereload listening no port: 35729`);
  34. });
  35. lrserver.watch([
  36. join(root, 'src'),
  37. join(root, 'public')
  38. ]);
  39. }
  40.  
  41. }
  42.  
  43. throng({
  44. workers: WORKERS,
  45. lifetime: Infinity,
  46. grace: 4000
  47. }, start);
Add Comment
Please, Sign In to add comment