-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
61 lines (52 loc) · 1.41 KB
/
index.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
'use strict';
const createSandbox = () => {
const sandbox = {
console,
setTimeout,
clearTimeout,
setInterval,
clearInterval
};
Object.defineProperty(sandbox, 'module', {
enumerable: true,
configurable: false,
writable: false,
value: Object.create(null)
});
sandbox.module.exports = Object.create(null);
sandbox.exports = sandbox.module.exports;
exposeRemoteServices(sandbox);
return sandbox;
};
const exposeRemoteServices = (sandbox) => {
if (process.env.GLITCHD_TOKEN === undefined) {
return;
}
const services = require('glitchd-client-node');
sandbox.Buffer = Buffer;
Object.defineProperty(sandbox, 'glitchd', {
value: Object.create(null, {
items: {
value: new services.ItemsStore('services.js13kgames.com:13312', process.env.GLITCHD_TOKEN)
}
})
});
};
require('fs').readFile('./dist/server-min.js', 'utf8', (err, code) => {
if (err) {
throw err
}
const
express = require('express'),
app = express(),
server = require('http').Server(app),
io = require('socket.io')(server),
sandbox = createSandbox();
require('vm').runInNewContext(code, sandbox);
io.on('connection', sandbox.module.exports);
app.set('port', (process.env.PORT || 3000));
app.use(express.static('dist'));
server.listen(app.get('port'), () => {
console.log('Server started at port: ' + app.get('port'));
});
});