You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
4.3 KiB

5 years ago
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const express = require("express");
const bodyParser = require("body-parser");
const helmet = require("helmet");
const cookieParser = require("cookie-parser");
5 years ago
const cors = require("cors");
const path = require("path");
const logger_1 = require("./src/utils/logger");
const hub_1 = require("./src/hub");
const setup_1 = require("./src/utils/setup");
const controllers = require("./src/controllers");
const socket = require("./src/utils/socket");
const network = require("./src/network");
const auth_1 = require("./src/auth");
5 years ago
const env = process.env.NODE_ENV || 'development';
const config = require(path.join(__dirname, 'config/app.json'))[env];
const port = process.env.PORT || config.node_http_port || 3001;
4 years ago
console.log("=> env:", env);
console.log('=> process.env.PORT:', process.env.PORT);
console.log('=> config.node_http_port:', config.node_http_port);
5 years ago
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
var i = 0;
// START SETUP!
4 years ago
function start() {
5 years ago
return __awaiter(this, void 0, void 0, function* () {
yield setup_1.setupDatabase();
4 years ago
connectToLND();
hub_1.pingHubInterval(15000);
});
}
start();
function connectToLND() {
return __awaiter(this, void 0, void 0, function* () {
5 years ago
i++;
console.log(`=> [lnd] connecting... attempt #${i}`);
try {
yield network.initGrpcSubscriptions(); // LND
yield mainSetup(); // DB + express
yield network.initTribesSubscriptions(); // MQTT
5 years ago
}
catch (e) {
if (e.details) {
console.log(`=> [lnd] error details: ${e.details}`);
}
else {
console.log(`=> [lnd] error: ${e.message}`);
}
5 years ago
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
yield connectToLND();
}), 2000);
}
});
}
function mainSetup() {
return __awaiter(this, void 0, void 0, function* () {
if (config.hub_api_url) {
// pingHubInterval(15000)
5 years ago
hub_1.checkInvitesHubInterval(5000);
}
yield setupApp();
setup_1.setupDone();
5 years ago
});
}
function setupApp() {
return __awaiter(this, void 0, void 0, function* () {
const app = express();
const server = require("http").Server(app);
app.use(helmet());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(logger_1.default);
app.use(cors({
allowedHeaders: ['X-Requested-With', 'Content-Type', 'Accept', 'x-user-token']
}));
5 years ago
app.use(cookieParser());
if (env != 'development') {
app.use(auth_1.authModule);
5 years ago
}
app.use('/static', express.static('public'));
app.get('/app', (req, res) => res.send('INDEX'));
5 years ago
server.listen(port, (err) => {
if (err)
throw err;
/* eslint-disable no-console */
console.log(`Node listening on ${port}.`);
});
// start all routes!
if (!config.unlock) {
controllers.set(app);
socket.connect(server);
5 years ago
}
else {
app.post('/unlock', function (req, res) {
return __awaiter(this, void 0, void 0, function* () {
const ok = yield auth_1.unlocker(req, res);
if (ok) {
controllers.set(app);
socket.connect(server);
}
});
});
5 years ago
}
});
}
//# sourceMappingURL=app.js.map