2018-09-15 03:31:01 +02:00
|
|
|
const path = require("path");
|
|
|
|
const express = require("express");
|
|
|
|
const bodyParser = require("body-parser");
|
2019-02-24 14:16:41 +01:00
|
|
|
const cookieParser = require("cookie-parser");
|
|
|
|
const common = require("./common");
|
2018-09-15 03:31:01 +02:00
|
|
|
const app = express();
|
|
|
|
|
|
|
|
//Declare all Routes here
|
2019-01-01 17:26:51 +01:00
|
|
|
const authenticateRoutes = require("./routes/authenticate");
|
2018-09-15 03:31:01 +02:00
|
|
|
const infoRoutes = require("./routes/getInfo");
|
|
|
|
const channelsRoutes = require("./routes/channels");
|
|
|
|
const peersRoutes = require("./routes/peers");
|
|
|
|
const feesRoutes = require("./routes/fees");
|
|
|
|
const balanceRoutes = require("./routes/balance");
|
|
|
|
const walletRoutes = require("./routes/wallet");
|
2018-11-05 00:47:00 +01:00
|
|
|
const graphRoutes = require("./routes/graph");
|
2018-09-27 04:02:46 +02:00
|
|
|
const newAddressRoutes = require("./routes/newAddress");
|
|
|
|
const transactionsRoutes = require("./routes/transactions");
|
2018-10-10 02:08:05 +02:00
|
|
|
const payReqRoutes = require("./routes/payReq");
|
|
|
|
const paymentsRoutes = require("./routes/payments");
|
2019-01-01 17:26:51 +01:00
|
|
|
const RTLConfRoutes = require("./routes/RTLConf");
|
2018-11-23 02:36:28 +01:00
|
|
|
const invoiceRoutes = require("./routes/invoices");
|
2019-01-23 04:28:45 +01:00
|
|
|
const switchRoutes = require("./routes/switch");
|
2019-03-02 18:55:19 +01:00
|
|
|
const baseHref = "/rtl/";
|
|
|
|
const apiRoot = baseHref + "api/";
|
2019-02-24 04:58:51 +01:00
|
|
|
|
2019-02-24 18:00:39 +01:00
|
|
|
app.use(cookieParser(common.secret_key));
|
2018-09-15 03:31:01 +02:00
|
|
|
app.use(bodyParser.json());
|
|
|
|
app.use(bodyParser.urlencoded({ extended: false }));
|
2019-02-24 04:58:51 +01:00
|
|
|
app.use(baseHref, express.static(path.join(__dirname, "angular")));
|
2018-09-15 03:31:01 +02: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-02 01:11:28 +02:00
|
|
|
"Origin, X-Requested-With, Content-Type, Accept, Authorization, filePath"
|
2018-09-15 03:31:01 +02: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
|
|
|
|
|
|
|
|
// Use declared routes here
|
2019-02-22 01:32:54 +01:00
|
|
|
app.use(apiRoot + "authenticate", authenticateRoutes);
|
|
|
|
app.use(apiRoot + "getinfo", infoRoutes);
|
|
|
|
app.use(apiRoot + "channels", channelsRoutes);
|
|
|
|
app.use(apiRoot + "peers", peersRoutes);
|
|
|
|
app.use(apiRoot + "fees", feesRoutes);
|
|
|
|
app.use(apiRoot + "balance", balanceRoutes);
|
|
|
|
app.use(apiRoot + "wallet", walletRoutes);
|
|
|
|
app.use(apiRoot + "network", graphRoutes);
|
|
|
|
app.use(apiRoot + "newaddress", newAddressRoutes);
|
|
|
|
app.use(apiRoot + "transactions", transactionsRoutes);
|
|
|
|
app.use(apiRoot + "payreq", payReqRoutes);
|
|
|
|
app.use(apiRoot + "payments", paymentsRoutes);
|
|
|
|
app.use(apiRoot + "conf", RTLConfRoutes);
|
|
|
|
app.use(apiRoot + "invoices", invoiceRoutes);
|
|
|
|
app.use(apiRoot + "switch", switchRoutes);
|
2018-09-15 03:31:01 +02:00
|
|
|
|
|
|
|
// sending angular application when route doesn't match
|
|
|
|
app.use((req, res, next) => {
|
|
|
|
res.sendFile(path.join(__dirname, "angular", "index.html"));
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = app;
|