darkwire.io/src/app.js
Dan Seripap 4cee744b07 Support for encrypted file transfer
Accept file, blob decoding

Remove double init of window handler

Added confirmation/acceptance message

Add lazy IDs to transferred files for file owner

Added chat class- initial support for slash commands

Abstraction of chat to its own class

Removed underscore from vendors, switching to import. Increased username color values

Not localizing username, organizing slash commands

Keeping context

Support for symbols/emojis. Fixes #9

Added back npm scripts, added method to check if log messages contain usernames

Checks and balances

Better parsing of commands and organization of valid commands

Fixed #10 - Added running version on modal and about section, Updated disclaimer/wording, displaying public IP if available through server

File transfer pre-confirmation

Encrypting stringified object versus string
2016-02-23 15:59:01 -05:00

68 lines
1.6 KiB
JavaScript

import _ from 'underscore';
import express from 'express';
import mustacheExpress from 'mustache-express';
import Io from 'socket.io';
import http from 'http';
import shortid from 'shortid';
import favicon from 'serve-favicon';
import compression from 'compression';
import fs from 'fs';
import Room from './room';
const $CONFIG = {
port: process.env.port || 3000
};
const app = express();
const server = http.createServer(app);
const io = Io(server);
let rooms = [];
app.use(compression());
app.use(favicon(__dirname + '/public/favicon.ico'));
app.engine('mustache', mustacheExpress());
app.set('view engine', 'mustache');
app.set('views', __dirname + '/views');
app.use(express.static(__dirname + '/public'));
function generateNewRoom(req, res, id) {
const room = new Room(io, id);
rooms.push(room);
console.log('generating new room');
room.on('empty', function() {
rooms = _.without(rooms, _.findWhere(rooms, {_id: room._id}));
});
return res.redirect(`/${id}`);
}
app.get('/', (req, res) => {
const id = shortid.generate();
generateNewRoom(req, res, id);
});
app.get('/:roomId', (req, res) => {
const roomId = req.params.roomId || false;
let roomExists = _.findWhere(rooms, {_id: roomId}) || false;
if (roomExists) {
return res.render('index', {
APP: {
version: process.env.npm_package_version,
ip: req.headers['x-forwarded-for']
},
username: shortid.generate()
});
}
return res.redirect('/');
});
server.listen($CONFIG.port, () => {
console.log(`darkwire is online on port ${$CONFIG.port}.`);
});