aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorMarvin Borner2019-01-26 20:36:31 +0100
committerMarvin Borner2019-01-26 20:36:31 +0100
commit31d6e5e9a619d5680001b84c5131a7b5b151ca29 (patch)
treedf1aedaf3a579817bd1b06eb935f868b652e99b5 /src
parent677689257a38cb8b8cf06a5c8d4ad2398381e41d (diff)
Cleaned up code for deployment
Diffstat (limited to 'src')
-rw-r--r--src/app.js40
-rw-r--r--src/index.js48
-rw-r--r--src/routes.js24
3 files changed, 45 insertions, 67 deletions
diff --git a/src/app.js b/src/app.js
deleted file mode 100644
index 0b0b3cd..0000000
--- a/src/app.js
+++ /dev/null
@@ -1,40 +0,0 @@
-import express from 'express';
-import path from 'path';
-import logger from 'morgan';
-import bodyParser from 'body-parser';
-import routes from './routes';
-
-const app = express();
-app.disable('x-powered-by');
-
-// 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
- });
-});
-
-export default app;
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
+ });
+});
diff --git a/src/routes.js b/src/routes.js
index c6590da..ef00e68 100644
--- a/src/routes.js
+++ b/src/routes.js
@@ -9,28 +9,4 @@ routes.get('/', (req, res) => {
res.render('index');
});
-/**
- * GET /list
- *
- * This is a sample route demonstrating
- * a simple approach to error handling and testing
- * the global error handler. You most certainly want to
- * create different/better error handlers depending on
- * your use case.
- */
-routes.get('/list', (req, res, next) => {
- const {title} = req.query;
-
- if (title == null || title === '') {
- // You probably want to set the response HTTP status to 400 Bad Request
- // or 422 Unprocessable Entity instead of the default 500 of
- // the global error handler (e.g check out https://github.com/kbariotis/throw.js).
- // This is just for demo purposes.
- next(new Error('The "title" parameter is required'));
- return;
- }
-
- res.render('index', {title});
-});
-
export default routes;