cherry-pick commit from Bellisario

This commit is contained in:
schlagmichdoch 2022-12-23 05:33:36 +01:00
parent 947e088aeb
commit 7283ab2c49

View file

@ -12,14 +12,46 @@ process.on('SIGTERM', () => {
process.exit(0)
})
// Handle APP ERRORS
process.on('uncaughtException', (error, origin) => {
console.log('----- Uncaught exception -----')
console.log(error)
console.log('----- Exception origin -----')
console.log(origin)
})
process.on('unhandledRejection', (reason, promise) => {
console.log('----- Unhandled Rejection at -----')
console.log(promise)
console.log('----- Reason -----')
console.log(reason)
})
const express = require('express');
const http = require('http');
const app = express();
const port = process.env.PORT || 3000;
app.use(express.static('public'));
app.use(function(req, res) {
res.redirect('/');
});
app.get('/', (req, res) => {
res.sendFile('index.html');
});
const server = http.createServer(app);
server.listen(port);
const parser = require('ua-parser-js');
const { uniqueNamesGenerator, animals, colors } = require('unique-names-generator');
class SnapdropServer {
constructor(host, port) {
constructor() {
const WebSocket = require('ws');
this._wss = new WebSocket.Server({ host: host, port: port });
this._wss = new WebSocket.Server({ server });
this._wss.on('connection', (socket, request) => this._onConnection(new Peer(socket, request)));
this._wss.on('headers', (headers, response) => this._onHeaders(headers, response));
@ -334,4 +366,4 @@ Object.defineProperty(String.prototype, 'hashCode', {
}
});
const server = new SnapdropServer(process.env.HOST || null, process.env.PORT || 3000);
new SnapdropServer();