2018-09-15 01:31:01 +00:00
|
|
|
const path = require("path");
|
|
|
|
const express = require("express");
|
|
|
|
const bodyParser = require("body-parser");
|
2019-02-24 13:16:41 +00:00
|
|
|
const cookieParser = require("cookie-parser");
|
|
|
|
const common = require("./common");
|
2018-09-15 01:31:01 +00:00
|
|
|
const app = express();
|
2019-09-01 17:01:38 +00:00
|
|
|
const baseHref = "/rtl/";
|
|
|
|
const apiRoot = baseHref + "api/";
|
|
|
|
const apiLNDRoot = baseHref + "api/lnd/";
|
|
|
|
const apiCLRoot = baseHref + "api/cl/";
|
2018-09-15 01:31:01 +00:00
|
|
|
|
2019-01-01 16:26:51 +00:00
|
|
|
const authenticateRoutes = require("./routes/authenticate");
|
|
|
|
const RTLConfRoutes = require("./routes/RTLConf");
|
2019-09-01 17:01:38 +00:00
|
|
|
const infoRoutes = require("./routes/lnd/getInfo");
|
|
|
|
const channelsRoutes = require("./routes/lnd/channels");
|
|
|
|
const channelsBackupRoutes = require("./routes/lnd/channelsBackup");
|
|
|
|
const peersRoutes = require("./routes/lnd/peers");
|
|
|
|
const feesRoutes = require("./routes/lnd/fees");
|
|
|
|
const balanceRoutes = require("./routes/lnd/balance");
|
|
|
|
const walletRoutes = require("./routes/lnd/wallet");
|
|
|
|
const graphRoutes = require("./routes/lnd/graph");
|
|
|
|
const newAddressRoutes = require("./routes/lnd/newAddress");
|
|
|
|
const transactionsRoutes = require("./routes/lnd/transactions");
|
|
|
|
const payReqRoutes = require("./routes/lnd/payReq");
|
|
|
|
const paymentsRoutes = require("./routes/lnd/payments");
|
|
|
|
const invoiceRoutes = require("./routes/lnd/invoices");
|
|
|
|
const switchRoutes = require("./routes/lnd/switch");
|
|
|
|
|
|
|
|
const infoCLRoutes = require("./routes/c-lightning/getInfo");
|
|
|
|
const feesCLRoutes = require("./routes/c-lightning/fees");
|
2019-09-02 04:11:37 +00:00
|
|
|
const balanceCLRoutes = require("./routes/c-lightning/balance");
|
|
|
|
const channelsCLRoutes = require("./routes/c-lightning/channels");
|
2019-09-07 21:31:32 +00:00
|
|
|
const invoicesCLRoutes = require("./routes/c-lightning/invoices");
|
2019-09-08 19:09:00 +00:00
|
|
|
const onChainCLRoutes = require("./routes/c-lightning/onchain");
|
2019-09-07 21:31:32 +00:00
|
|
|
const paymentsCLRoutes = require("./routes/c-lightning/payments");
|
|
|
|
const peersCLRoutes = require("./routes/c-lightning/peers");
|
2019-09-08 19:09:00 +00:00
|
|
|
const networkCLRoutes = require("./routes/c-lightning/network");
|
2019-02-24 03:58:51 +00:00
|
|
|
|
2019-02-24 17:00:39 +00:00
|
|
|
app.use(cookieParser(common.secret_key));
|
2018-09-15 01:31:01 +00:00
|
|
|
app.use(bodyParser.json());
|
|
|
|
app.use(bodyParser.urlencoded({ extended: false }));
|
2019-02-24 03:58:51 +00:00
|
|
|
app.use(baseHref, express.static(path.join(__dirname, "angular")));
|
2018-09-15 01:31:01 +00:00
|
|
|
|
|
|
|
// CORS fix, Only required for developement due to separate backend and frontend servers
|
|
|
|
app.use((req, res, next) => {
|
|
|
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
|
res.setHeader(
|
|
|
|
"Access-Control-Allow-Headers",
|
2018-10-01 23:11:28 +00:00
|
|
|
"Origin, X-Requested-With, Content-Type, Accept, Authorization, filePath"
|
2018-09-15 01:31:01 +00:00
|
|
|
);
|
|
|
|
res.setHeader(
|
|
|
|
"Access-Control-Allow-Methods",
|
|
|
|
"GET, POST, PATCH, PUT, DELETE, OPTIONS"
|
|
|
|
);
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
// CORS fix, Only required for developement due to separate backend and frontend servers
|
|
|
|
|
2019-02-22 00:32:54 +00:00
|
|
|
app.use(apiRoot + "authenticate", authenticateRoutes);
|
|
|
|
app.use(apiRoot + "conf", RTLConfRoutes);
|
2019-09-01 17:01:38 +00:00
|
|
|
app.use(apiLNDRoot + "getinfo", infoRoutes);
|
|
|
|
app.use(apiLNDRoot + "channels", channelsRoutes);
|
|
|
|
app.use(apiLNDRoot + "channels/backup", channelsBackupRoutes);
|
|
|
|
app.use(apiLNDRoot + "peers", peersRoutes);
|
|
|
|
app.use(apiLNDRoot + "fees", feesRoutes);
|
|
|
|
app.use(apiLNDRoot + "balance", balanceRoutes);
|
|
|
|
app.use(apiLNDRoot + "wallet", walletRoutes);
|
|
|
|
app.use(apiLNDRoot + "network", graphRoutes);
|
|
|
|
app.use(apiLNDRoot + "newaddress", newAddressRoutes);
|
|
|
|
app.use(apiLNDRoot + "transactions", transactionsRoutes);
|
|
|
|
app.use(apiLNDRoot + "payreq", payReqRoutes);
|
|
|
|
app.use(apiLNDRoot + "payments", paymentsRoutes);
|
|
|
|
app.use(apiLNDRoot + "invoices", invoiceRoutes);
|
|
|
|
app.use(apiLNDRoot + "switch", switchRoutes);
|
|
|
|
|
|
|
|
app.use(apiCLRoot + "getinfo", infoCLRoutes);
|
|
|
|
app.use(apiCLRoot + "fees", feesCLRoutes);
|
2019-09-02 04:11:37 +00:00
|
|
|
app.use(apiCLRoot + "balance", balanceCLRoutes);
|
|
|
|
app.use(apiCLRoot + "channels", channelsCLRoutes);
|
2019-09-07 21:31:32 +00:00
|
|
|
app.use(apiCLRoot + "invoices", invoicesCLRoutes);
|
2019-09-08 19:09:00 +00:00
|
|
|
app.use(apiCLRoot + "onchain", onChainCLRoutes);
|
2019-09-07 21:31:32 +00:00
|
|
|
app.use(apiCLRoot + "payments", paymentsCLRoutes);
|
|
|
|
app.use(apiCLRoot + "peers", peersCLRoutes);
|
2019-09-08 19:09:00 +00:00
|
|
|
app.use(apiCLRoot + "network", networkCLRoutes);
|
2018-09-15 01:31:01 +00:00
|
|
|
|
|
|
|
app.use((req, res, next) => {
|
|
|
|
res.sendFile(path.join(__dirname, "angular", "index.html"));
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = app;
|