test-ros-server.js
2.3 KB
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
// Change the working directory before importing ROS because the version of
// realm-js used by ROS captures the working directory on load (this has since
// been fixed)
const tmp = require('tmp');
const dataDir = tmp.dirSync().name;
process.chdir(dataDir);
const ROS = require('realm-object-server');
const NodeRSA = require('node-rsa');
const fs = require('fs');
const os = require('os');
const path = require('path');
// Bypass the mandatory email prompt.
process.env.ROS_TOS_EMAIL_ADDRESS = 'ci@realm.io';
process.env.DOCKER_DATA_PATH = '/tmp';
// Don't bother calling fsync() because we're throwing away all the files
// between runs anyway
process.env.REALM_DISABLE_SYNC_TO_DISK = 'true';
// Workaround for <https://github.com/realm/realm-object-server-private/issues/950>.
process.env.ROS_SUPERAGENT_RETRY_DELAY = '0';
// Enable timestamps in the logs
process.env.ROS_LOG_TIMESTAMP = '1';
if (!process.env.SYNC_WORKER_FEATURE_TOKEN) {
try {
require(os.homedir() + '/.ros-feature-token.js');
}
catch (e) {
console.error('ROS feature token not found. Running Object Server tests requires setting the SYNC_WORKER_FEATURE_TOKEN environment variable.');
process.exit(1);
}
}
fs.mkdirSync(`${dataDir}/keys`);
const jwtKey = new NodeRSA({b: 1024});
fs.writeFileSync(`${dataDir}/keys/jwt.pem`, jwtKey.exportKey('private'));
const server = new ROS.BasicServer();
server.start({
// The desired logging threshold. Can be one of: all, trace, debug, detail, info, warn, error, fatal, off)
logLevel: process.env.ROS_LOG_LEVEL || 'off',
// For all the full list of configuration parameters see:
// https://realm.io/docs/realm-object-server/latest/api/ros/interfaces/serverconfig.html
address: '0.0.0.0',
port: 9080,
dataPath: dataDir,
authProviders: [
new ROS.auth.AnonymousAuthProvider(),
new ROS.auth.NicknameAuthProvider(),
new ROS.auth.DebugAuthProvider(),
new ROS.auth.PasswordAuthProvider({
autoCreateAdminUser: true,
}),
new ROS.auth.JwtAuthProvider({
publicKey: jwtKey.exportKey('public')
}),
],
autoKeyGen: true,
}).then(() => {
console.log(`Started: ${dataDir}`);
fs.closeSync(1);
}).catch(err => {
console.error(`Error starting Realm Object Server: ${err.message}`)
});