140 lines
4.1 KiB
JavaScript
140 lines
4.1 KiB
JavaScript
const express = require("express");
|
|
const cors = require("cors");
|
|
const bodyParser = require("body-parser");
|
|
const path = require("path");
|
|
const compression = require("compression");
|
|
const twilio = require("twilio");
|
|
global.fetch = require("node-fetch");
|
|
var fb = require("./server/firebase/firebase-handler");
|
|
|
|
//var enforce = require("express-sslify");
|
|
|
|
require("dotenv").config({
|
|
path: path.resolve(
|
|
process.cwd(),
|
|
`.env.${process.env.NODE_ENV || "development"}`
|
|
),
|
|
});
|
|
|
|
const https = require("https");
|
|
const fs = require("fs");
|
|
|
|
const app = express();
|
|
const port = process.env.PORT || 5000;
|
|
//const port = 5000;
|
|
|
|
app.use(fb.validateFirebaseIdToken);
|
|
app.use(compression());
|
|
app.use(bodyParser.json({ limit: "50mb" }));
|
|
app.use(bodyParser.urlencoded({ limit: "50mb", extended: true }));
|
|
//app.use(enforce.HTTPS({ trustProtoHeader: true }));
|
|
app.use(cors());
|
|
|
|
//Email Based Paths.
|
|
var sendEmail = require("./sendemail.js");
|
|
app.post("/sendemail", sendEmail.sendEmail);
|
|
|
|
//Test route to ensure Express is responding.
|
|
app.get("/test", async function (req, res) {
|
|
res.status(200).send("OK");
|
|
});
|
|
const test = require("./server/_test/test.js");
|
|
app.post("/test", test.testResponse);
|
|
|
|
//Accounting-IIF
|
|
const accountingIIF = require("./server/accounting/iif/iif");
|
|
app.post("/accounting/iif/receivables", accountingIIF.receivables);
|
|
|
|
//Accounting Qbxml
|
|
const accountQbxml = require("./server/accounting/qbxml/qbxml");
|
|
app.post("/accounting/qbxml/receivables", accountQbxml.receivables);
|
|
app.post("/accounting/qbxml/payables", accountQbxml.payables);
|
|
app.post("/accounting/qbxml/payments", accountQbxml.payments);
|
|
|
|
//Cloudinary Media Paths
|
|
var media = require("./server/media/media");
|
|
app.post("/media/sign", media.createSignedUploadURL);
|
|
app.post("/media/download", media.downloadFiles);
|
|
|
|
//SMS/Twilio Paths
|
|
var smsReceive = require("./server/sms/receive");
|
|
app.post(
|
|
"/sms/receive",
|
|
twilio.webhook({ validate: process.env.NODE_ENV === "PRODUCTION" }),
|
|
smsReceive.receive
|
|
);
|
|
var smsSend = require("./server/sms/send");
|
|
app.post("/sms/send", smsSend.send);
|
|
var smsStatus = require("./server/sms/status");
|
|
app.post(
|
|
"/sms/status",
|
|
twilio.webhook({ validate: process.env.NODE_ENV === "PRODUCTION" }),
|
|
smsStatus.status
|
|
);
|
|
|
|
//Scheduling
|
|
var scheduling = require("./server/scheduling/scheduling-job");
|
|
app.post("/scheduling/job", scheduling.job);
|
|
|
|
//Handlebars Paths for Email/Report Rendering
|
|
var renderHandlebars = require("./server/render/renderHandlebars");
|
|
app.post("/render", renderHandlebars.render);
|
|
|
|
app.post("/notifications/send", fb.sendNotification);
|
|
|
|
//Stripe Processing
|
|
var stripe = require("./server/stripe/payment");
|
|
app.post("/stripe/payment", stripe.payment);
|
|
app.post("/stripe/mobilepayment", stripe.mobile_payment);
|
|
|
|
//Tech Console
|
|
var tech = require("./server/tech/tech");
|
|
app.post("/tech/login", tech.techLogin);
|
|
|
|
var utils = require("./server/utils/utils");
|
|
app.post("/utils/time", utils.servertime);
|
|
|
|
//Serve React App if in Production
|
|
if (process.env.NODE_ENV === "production") {
|
|
app.use(express.static(path.join(__dirname, "client/build")));
|
|
app.use(express.static(path.join(__dirname, "admin/build")));
|
|
|
|
app.get("/service-worker.js", (req, res) => {
|
|
res.sendFile(path.resolve(__dirname, "..", "build", "service-worker.js"));
|
|
});
|
|
|
|
app.get("/admin*", function (req, res) {
|
|
res.sendFile(path.join(__dirname, "admin/build", "index.html"));
|
|
});
|
|
|
|
app.get("*", function (req, res) {
|
|
res.sendFile(path.join(__dirname, "client/build", "index.html"));
|
|
});
|
|
}
|
|
|
|
if (process.env.NODE_ENV === "production") {
|
|
app.listen(port, (error) => {
|
|
if (error) throw error;
|
|
console.log("[PRODUCTION] Server running on port " + port);
|
|
});
|
|
} else {
|
|
https
|
|
.createServer(
|
|
{
|
|
key: fs.readFileSync("./key.pem"),
|
|
cert: fs.readFileSync("./cert.pem"),
|
|
passphrase: "Wl0d8k@!",
|
|
},
|
|
app
|
|
)
|
|
.listen(port, (error) => {
|
|
if (error) throw error;
|
|
console.log("[DEV/STAGING] Mock HTTPS Server running on port " + port);
|
|
});
|
|
}
|
|
|
|
// app.listen(port, error => {
|
|
// if (error) throw error;
|
|
// console.log("Server running on port " + port);
|
|
// });
|