-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathliferay-stub.js
73 lines (65 loc) · 1.63 KB
/
liferay-stub.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
var express = require('express');
var port = process.env.EGS_PORT || 4000;
if (process.argv && process.argv[2])
{
port = process.argv[2];
}
var app = express();
function rawBody(req, res, next) {
req.setEncoding('utf8');
req.rawBody = '';
req.on('data', function(chunk) {
req.rawBody += chunk;
});
req.on('end', function(){
next();
});
}
app.use(rawBody);
app.post('/api/secure/jsonws/egs-portlet.gamebot', function(req, res) {
var ctype = req.header('Content-Type');
if (ctype !== "text/plain; charset=utf-8") {
var response = {
"Status": "Error",
"System Version": "0.1.0",
"Method": "update-gamestate",
"Format Error": "Invalid content type. Must be 'text/plain; charset=utf-8'. You sent: "+ctype,
"System Name": "ECCO Game Services"
}
res.send(response);
return;
}
var payload = JSON.parse(req.rawBody).params.payload;
var updates = payload.updates;
if (updates)
console.log(updates);
var response = {
"Status": "OK",
"System Version": "0.1.0",
"Method": "update-gamestate",
"Updates Processed": "1",
"System Name": "ECCO Game Services"
};
res.send(response);
});
app.get('/api/secure/jsonws/egs-portlet.gamingprofile/get', function(req, res) {
var results = {
gameInstanceId: "foo",
gamingId: "bar",
casId: "baz"
};
var email = req.param('email');
if (email) {
results.casId = email;
results.gamingId = {
"foo": "foo",
"bar": "bar"
}[email];
}
res.send(results);
});
app.all('/*', function(req, res, next) {
res.send('received');
});
app.listen(port);
console.log('server listening on: ' + port);