Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express');
- const Gun = require('gun');
- const join = require('path').join;
- const livereload = require('livereload');
- const PORT = process.env.PORT || 8080;
- const root = process.cwd();
- const throng = require('throng');
- const WORKERS = process.env.WEB_CONCURRENCY || 1;
- function start() {
- const app = express();
- app.use(Gun.serve);
- app.use(express.static(join(root, 'public')));
- app.use(express.static(join(root, 'node_modules')));
- app.use(express.static(join(root, 'src')));
- app.get('*', (req, res) => {
- res.sendFile(join(root, 'public', 'index.html'));
- });
- const server = app.listen(PORT, () => console.log(`server listening on port: ${PORT}`));
- Gun({
- web: server,
- localStorage: false
- });
- if (process.NODE_ENV !== 'production') {
- const lrserver = livereload.createServer({
- exts: ['html', 'css', 'js', 'mjs'],
- extensions: ['html', 'css', 'js', 'mjs']
- }, () => {
- console.log(`livereload listening no port: 35729`);
- });
- lrserver.watch([
- join(root, 'src'),
- join(root, 'public')
- ]);
- }
- }
- throng({
- workers: WORKERS,
- lifetime: Infinity,
- grace: 4000
- }, start);
Add Comment
Please, Sign In to add comment