forked from PeerServer/peer-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·85 lines (69 loc) · 2.41 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Set up bindings for real server.
* Handle handshake between clientServer and clientBrowser
*/
/* Load in dependencies */
var config = require('getconfig'),
http = require('http'),
fs = require('fs');
var app = require('express')();
/* Create the peer server for the app */
var PeerServer = require('peer').PeerServer;
var peerServer = new PeerServer({ port: 9000, debug: true });
/* Create the file server for the app */
var server = require('http').createServer(app);
var port = process.env.PORT || config.server.port || 5000;
/* Start the server at the port. */
server.listen(port, function() {
console.log('Server running at port ' + port);
});
/* Static file mappings */
app.param('filename');
app.get('/server', function(req, res) {
res.sendfile(__dirname + '/server/index.html');
});
app.get('/server/:filename(*)', function(req, res) {
var filename = __dirname + '/server/' + req.params.filename;
if (fs.existsSync(filename)) {
res.sendfile(filename);
} else {
res.sendfile(__dirname + '/server/index.html');
}
});
app.get('/template/:filename(*)', function(req, res) {
res.sendfile(__dirname + '/sample_servers/' + req.params.filename + '.zip');
});
app.get('/connect/:serverid(*)', function(req, res) {
var serverid = req.params.serverid;
res.sendfile(__dirname + '/client/index.html');
});
app.get('/client/:filename(*)', function(req, res) {
var filename = req.params.filename;
res.sendfile(__dirname + '/client/' + filename);
});
app.get('/shared/:filename(*)', function(req, res) {
var filename = req.params.filename;
res.sendfile(__dirname + '/shared/' + filename);
});
app.get('/home/:filename(*)', function(req, res) {
var filename = req.params.filename;
res.sendfile(__dirname + '/home/' + filename);
});
// /* Temporary mapping kept at the bottom just for testing test files
// outside of the server browser. */
// app.get('/test', function(req, res) {
// var filename = req.params.filename;
// res.sendfile(__dirname + '/test_files/wrapper.html');
// });
/* Temporary mapping kept at the bottom for testing. TODO remove. */
app.get('/test_files/:filename(*)', function(req, res) {
var filename = req.params.filename;
res.sendfile(__dirname + '/test_files/' + filename);
});
app.get("/", function(req, res) {
res.sendfile(__dirname + '/home/index.html');
})
/* Set UID of process from config if applicable */
if (config.uid) {
process.setuid(config.uid);
}