2
0
mirror of https://github.com/Ride-The-Lightning/RTL synced 2024-11-15 18:13:00 +00:00
RTL/app.js

72 lines
2.7 KiB
JavaScript
Raw Normal View History

2018-09-15 01:31:01 +00:00
const path = require("path");
const express = require("express");
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const common = require("./common");
2018-09-15 01:31:01 +00:00
const app = express();
//Declare all Routes here
2019-01-01 16:26:51 +00:00
const authenticateRoutes = require("./routes/authenticate");
2018-09-15 01:31:01 +00:00
const infoRoutes = require("./routes/getInfo");
const channelsRoutes = require("./routes/channels");
const channelsBackupRoutes = require("./routes/channelsBackup");
2018-09-15 01:31:01 +00:00
const peersRoutes = require("./routes/peers");
const feesRoutes = require("./routes/fees");
const balanceRoutes = require("./routes/balance");
const walletRoutes = require("./routes/wallet");
const graphRoutes = require("./routes/graph");
const newAddressRoutes = require("./routes/newAddress");
const transactionsRoutes = require("./routes/transactions");
const payReqRoutes = require("./routes/payReq");
const paymentsRoutes = require("./routes/payments");
2019-01-01 16:26:51 +00:00
const RTLConfRoutes = require("./routes/RTLConf");
const invoiceRoutes = require("./routes/invoices");
const switchRoutes = require("./routes/switch");
const baseHref = "/rtl/";
const apiRoot = baseHref + "api/";
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 }));
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
// Use declared routes here
2019-02-22 00:32:54 +00:00
app.use(apiRoot + "authenticate", authenticateRoutes);
app.use(apiRoot + "getinfo", infoRoutes);
app.use(apiRoot + "channels", channelsRoutes);
app.use(apiRoot + "channels/backup", channelsBackupRoutes);
2019-02-22 00:32:54 +00:00
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 01:31:01 +00: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;