aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/index.js')
-rw-r--r--src/index.js48
1 files changed, 45 insertions, 3 deletions
diff --git a/src/index.js b/src/index.js
index fbfb85e..c664485 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,4 +1,46 @@
-import app from './app';
+import {ExpressPeerServer} from "peer";
+import express from 'express';
+import path from 'path';
+import logger from 'morgan';
+import bodyParser from 'body-parser';
+import routes from './routes';
-const {PORT = 8080} = process.env;
-app.listen(PORT, () => console.log(`Listening on port ${PORT}`)); // eslint-disable-line no-console
+const app = express();
+app.disable('x-powered-by');
+
+const server = app.listen(8080, "0.0.0.0");
+const peerServer = ExpressPeerServer(server, {debug: true});
+
+peerServer.on('connection', id => console.log('New connection: ' + id));
+
+app.use('/api', peerServer);
+
+// View engine setup
+app.set('views', path.join(__dirname, '../views'));
+app.set('view engine', 'pug');
+
+app.use(logger('dev', {
+ skip: () => app.get('env') === 'test'
+}));
+app.use(bodyParser.json());
+app.use(bodyParser.urlencoded({extended: false}));
+app.use(express.static(path.join(__dirname, '../dist')));
+
+// Routes
+app.use('/', routes);
+
+// Catch 404 and forward to error handler
+app.use((req, res, next) => {
+ const err = new Error('Not Found');
+ err.status = 404;
+ next(err);
+});
+
+// Error handler
+app.use((err, req, res, next) => { // eslint-disable-line no-unused-vars
+ res
+ .status(err.status || 500)
+ .render('error', {
+ message: err.message
+ });
+});