forked from energychain/casa-corrently
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstandalone.js
executable file
·60 lines (48 loc) · 1.65 KB
/
standalone.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
#!/usr/bin/env node
const CasaCorrently = require("./app.js");
const fs = require("fs");
const winston = require("winston");
let doupdates = true;
const { createLogger, format, transports } = require('winston');
const { combine, timestamp, label, prettyPrint } = format;
const logger = createLogger({
transports: [
new winston.transports.Console(),
new winston.transports.File({ filename: 'standalone.log' })
],
format: combine(
label({ label: 'casa-corrently-standalone' }),
timestamp(),
prettyPrint()
)
});
const console = new winston.transports.Console();
const fileExists = async path => !!(await fs.promises.stat(path).catch(e => false));
const boot = async function() {
let config = {status:'loading'};
if(typeof process.env.PORT !== 'undefined') {
port = process.env.PORT;
}
// UUID Persistence
if((process.argv.length == 3)&&(await fileExists(process.argv[2]))) {
config = JSON.parse(fs.readFileSync(process.argv[2]));
} else
if(await fileExists("./config.json")) {
config = JSON.parse(fs.readFileSync("./config.json"));
} else
if(await fileExists("./sample_config.json")) {
config = JSON.parse(fs.readFileSync("./sample_config.json"));
}
if(typeof config.uuid == 'undefined') {
config.uuid = Math.random(); // Due to node js incompatibility with nanoid or uuid this is a bad fix
config.uuid = (""+config.uuid).substring(2) + (Math.random());
}
if(typeof config.autoupdate !== 'undefined') {
doupdates = config.autoupdate;
}
logger.info("Starting Standalone");
const main = await CasaCorrently();
await main.server(config);
//await main.server(config,logger);
};
boot();