- Scaffolding.

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-01-22 16:38:26 -05:00
parent 166efdc877
commit 7f587680ca
3 changed files with 147 additions and 138 deletions

279
server.js
View File

@@ -12,10 +12,10 @@ const upload = multer();
//var enforce = require("express-sslify"); //var enforce = require("express-sslify");
require("dotenv").config({ require("dotenv").config({
path: path.resolve( path: path.resolve(
process.cwd(), process.cwd(),
`.env.${process.env.NODE_ENV || "development"}` `.env.${process.env.NODE_ENV || "development"}`
), ),
}); });
const app = express(); const app = express();
@@ -24,25 +24,25 @@ const port = process.env.PORT || 5000;
const http = require("http"); const http = require("http");
const server = http.createServer(app); const server = http.createServer(app);
const { Server } = require("socket.io"); const {Server} = require("socket.io");
const io = new Server(server, { const io = new Server(server, {
path: "/ws", path: "/ws",
cors: { cors: {
origin: [ origin: [
"https://test.imex.online", "https://test.imex.online",
"https://www.test.imex.online", "https://www.test.imex.online",
"http://localhost:3000", "http://localhost:3000",
"https://imex.online", "https://imex.online",
"https://www.imex.online", "https://www.imex.online",
"https://beta.test.imex.online", "https://beta.test.imex.online",
"https://www.beta.test.imex.online", "https://www.beta.test.imex.online",
"https://beta.imex.online", "https://beta.imex.online",
"https://www.beta.imex.online", "https://www.beta.imex.online",
], ],
methods: ["GET", "POST"], methods: ["GET", "POST"],
credentials: true, credentials: true,
exposedHeaders: ["set-cookie"], exposedHeaders: ["set-cookie"],
}, },
}); });
exports.io = io; exports.io = io;
require("./server/web-sockets/web-socket"); require("./server/web-sockets/web-socket");
@@ -50,116 +50,119 @@ require("./server/web-sockets/web-socket");
// app.use(fb.validateFirebaseIdToken); // app.use(fb.validateFirebaseIdToken);
app.use(compression()); app.use(compression());
app.use(cookieParser()); app.use(cookieParser());
app.use(bodyParser.json({ limit: "50mb" })); app.use(bodyParser.json({limit: "50mb"}));
app.use(bodyParser.urlencoded({ limit: "50mb", extended: true })); app.use(bodyParser.urlencoded({limit: "50mb", extended: true}));
// app.use(enforce.HTTPS({ trustProtoHeader: true })); // app.use(enforce.HTTPS({ trustProtoHeader: true }));
app.use( app.use(
cors({ credentials: true, exposedHeaders: ["set-cookie"] }) cors({credentials: true, exposedHeaders: ["set-cookie"]})
// cors({ // cors({
// credentials: true, // credentials: true,
// origin: [ // origin: [
// "https://test.imex.online", // "https://test.imex.online",
// "http://localhost:3000", // "http://localhost:3000",
// "https://imex.online", // "https://imex.online",
// ], // ],
// }) // })
); );
//Email Based Paths. //Email Based Paths.
var sendEmail = require("./server/email/sendemail.js"); const sendEmail = require("./server/email/sendemail.js");
app.post("/sendemail", fb.validateFirebaseIdToken, sendEmail.sendEmail); app.post("/sendemail", fb.validateFirebaseIdToken, sendEmail.sendEmail);
app.post("/emailbounce", bodyParser.text(), sendEmail.emailBounce); app.post("/emailbounce", bodyParser.text(), sendEmail.emailBounce);
//Test route to ensure Express is responding. //Test route to ensure Express is responding.
app.get("/test", async function (req, res) { app.get("/test", async (req, res) => {
const commit = require("child_process").execSync( const commit = require("child_process").execSync(
"git rev-parse --short HEAD" "git rev-parse --short HEAD"
); );
// console.log(app.get('trust proxy')); // console.log(app.get('trust proxy'));
// console.log("remoteAddress", req.socket.remoteAddress); // console.log("remoteAddress", req.socket.remoteAddress);
// console.log("X-Forwarded-For", req.header('x-forwarded-for')); // console.log("X-Forwarded-For", req.header('x-forwarded-for'));
logger.log("test-api-status", "DEBUG", "api", { commit }); logger.log("test-api-status", "DEBUG", "api", {commit});
// sendEmail.sendServerEmail({ // sendEmail.sendServerEmail({
// subject: `API Check - ${process.env.NODE_ENV}`, // subject: `API Check - ${process.env.NODE_ENV}`,
// text: `Server API check has come in. Remote IP: ${req.socket.remoteAddress}, X-Forwarded-For: ${req.header('x-forwarded-for')}`, // text: `Server API check has come in. Remote IP: ${req.socket.remoteAddress}, X-Forwarded-For: ${req.header('x-forwarded-for')}`,
// }); // });
sendEmail.sendServerEmail({ sendEmail.sendServerEmail({
subject: `API Check - ${process.env.NODE_ENV}`, subject: `API Check - ${process.env.NODE_ENV}`,
text: `Server API check has come in.`, text: `Server API check has come in.`,
}); });
res.status(200).send(`OK - ${commit}`); res.status(200).send(`OK - ${commit}`);
}); });
//Accounting Qbxml //Accounting Qbxml
const accountQbxml = require("./server/accounting/qbxml/qbxml"); const accountQbxml = require("./server/accounting/qbxml/qbxml");
app.post( app.post(
"/accounting/qbxml/receivables", "/accounting/qbxml/receivables",
fb.validateFirebaseIdToken, fb.validateFirebaseIdToken,
accountQbxml.receivables accountQbxml.receivables
); );
app.post( app.post(
"/accounting/qbxml/payables", "/accounting/qbxml/payables",
fb.validateFirebaseIdToken, fb.validateFirebaseIdToken,
accountQbxml.payables accountQbxml.payables
); );
app.post( app.post(
"/accounting/qbxml/payments", "/accounting/qbxml/payments",
fb.validateFirebaseIdToken, fb.validateFirebaseIdToken,
accountQbxml.payments accountQbxml.payments
); );
//Cloudinary Media Paths //Cloudinary Media Paths
var media = require("./server/media/media"); const media = require("./server/media/media");
app.post( app.post(
"/media/sign", "/media/sign",
fb.validateFirebaseIdToken, fb.validateFirebaseIdToken,
media.createSignedUploadURL media.createSignedUploadURL
); );
app.post("/media/download", fb.validateFirebaseIdToken, media.downloadFiles); app.post("/media/download", fb.validateFirebaseIdToken, media.downloadFiles);
app.post("/media/rename", fb.validateFirebaseIdToken, media.renameKeys); app.post("/media/rename", fb.validateFirebaseIdToken, media.renameKeys);
app.post("/media/delete", fb.validateFirebaseIdToken, media.deleteFiles); app.post("/media/delete", fb.validateFirebaseIdToken, media.deleteFiles);
//SMS/Twilio Paths //SMS/Twilio Paths
var smsReceive = require("./server/sms/receive"); const smsReceive = require("./server/sms/receive");
app.post( app.post(
"/sms/receive", "/sms/receive",
twilio.webhook({ validate: process.env.NODE_ENV === "PRODUCTION" }), twilio.webhook({validate: process.env.NODE_ENV === "PRODUCTION"}),
smsReceive.receive smsReceive.receive
); );
var smsSend = require("./server/sms/send"); const smsSend = require("./server/sms/send");
app.post("/sms/send", fb.validateFirebaseIdToken, smsSend.send); app.post("/sms/send", fb.validateFirebaseIdToken, smsSend.send);
var smsStatus = require("./server/sms/status"); const smsStatus = require("./server/sms/status");
app.post( app.post(
"/sms/status", "/sms/status",
twilio.webhook({ validate: process.env.NODE_ENV === "PRODUCTION" }), twilio.webhook({validate: process.env.NODE_ENV === "PRODUCTION"}),
smsStatus.status smsStatus.status
); );
app.post( app.post(
"/sms/markConversationRead", "/sms/markConversationRead",
fb.validateFirebaseIdToken, fb.validateFirebaseIdToken,
smsStatus.markConversationRead smsStatus.markConversationRead
); );
var job = require("./server/job/job"); const job = require("./server/job/job");
app.post("/job/totals", fb.validateFirebaseIdToken, job.totals); app.post("/job/totals", fb.validateFirebaseIdToken, job.totals);
app.post( app.post(
"/job/statustransition", "/job/statustransition",
// fb.validateFirebaseIdToken, // fb.validateFirebaseIdToken,
job.statustransition job.statustransition
); );
app.post("/job/totalsssu", fb.validateFirebaseIdToken, job.totalsSsu); app.post("/job/totalsssu", fb.validateFirebaseIdToken, job.totalsSsu);
app.post("/job/costing", fb.validateFirebaseIdToken, job.costing); app.post("/job/costing", fb.validateFirebaseIdToken, job.costing);
app.get("/job/lifecycle", fb.validateFirebaseIdToken, job.lifecycle);
app.post("/job/costingmulti", fb.validateFirebaseIdToken, job.costingmulti); app.post("/job/costingmulti", fb.validateFirebaseIdToken, job.costingmulti);
var partsScan = require("./server/parts-scan/parts-scan"); const partsScan = require("./server/parts-scan/parts-scan");
app.post("/job/partsscan", fb.validateFirebaseIdToken, partsScan.partsScan); app.post("/job/partsscan", fb.validateFirebaseIdToken, partsScan.partsScan);
//Scheduling //Scheduling
var scheduling = require("./server/scheduling/scheduling-job"); const scheduling = require("./server/scheduling/scheduling-job");
app.post("/scheduling/job", fb.validateFirebaseIdToken, scheduling.job); app.post("/scheduling/job", fb.validateFirebaseIdToken, scheduling.job);
//Handlebars Paths for Email/Report Rendering //Handlebars Paths for Email/Report Rendering
// var renderHandlebars = require("./server/render/renderHandlebars"); // var renderHandlebars = require("./server/render/renderHandlebars");
// app.post("/render", fb.validateFirebaseIdToken, renderHandlebars.render); // app.post("/render", fb.validateFirebaseIdToken, renderHandlebars.render);
var inlineCss = require("./server/render/inlinecss"); const inlineCss = require("./server/render/inlinecss");
app.post("/render/inlinecss", fb.validateFirebaseIdToken, inlineCss.inlinecss); app.post("/render/inlinecss", fb.validateFirebaseIdToken, inlineCss.inlinecss);
// app.post( // app.post(
@@ -169,37 +172,37 @@ app.post("/render/inlinecss", fb.validateFirebaseIdToken, inlineCss.inlinecss);
// ); // );
app.post("/notifications/subscribe", fb.validateFirebaseIdToken, fb.subscribe); app.post("/notifications/subscribe", fb.validateFirebaseIdToken, fb.subscribe);
app.post( app.post(
"/notifications/unsubscribe", "/notifications/unsubscribe",
fb.validateFirebaseIdToken, fb.validateFirebaseIdToken,
fb.unsubscribe fb.unsubscribe
); );
app.post("/adm/updateuser", fb.validateFirebaseIdToken, fb.updateUser); app.post("/adm/updateuser", fb.validateFirebaseIdToken, fb.updateUser);
app.post("/adm/getuser", fb.validateFirebaseIdToken, fb.getUser); app.post("/adm/getuser", fb.validateFirebaseIdToken, fb.getUser);
app.post("/adm/createuser", fb.validateFirebaseIdToken, fb.createUser); app.post("/adm/createuser", fb.validateFirebaseIdToken, fb.createUser);
const adm = require("./server/admin/adminops"); const adm = require("./server/admin/adminops");
app.post( app.post(
"/adm/createassociation", "/adm/createassociation",
fb.validateFirebaseIdToken, fb.validateFirebaseIdToken,
fb.validateAdmin, fb.validateAdmin,
adm.createAssociation adm.createAssociation
); );
app.post( app.post(
"/adm/createshop", "/adm/createshop",
fb.validateFirebaseIdToken, fb.validateFirebaseIdToken,
fb.validateAdmin, fb.validateAdmin,
adm.createShop adm.createShop
); );
app.post( app.post(
"/adm/updateshop", "/adm/updateshop",
fb.validateFirebaseIdToken, fb.validateFirebaseIdToken,
fb.validateAdmin, fb.validateAdmin,
adm.updateShop adm.updateShop
); );
app.post( app.post(
"/adm/updatecounter", "/adm/updatecounter",
fb.validateFirebaseIdToken, fb.validateFirebaseIdToken,
fb.validateAdmin, fb.validateAdmin,
adm.updateCounter adm.updateCounter
); );
//Stripe Processing //Stripe Processing
@@ -212,88 +215,88 @@ app.post(
// ); // );
//Tech Console //Tech Console
var tech = require("./server/tech/tech"); const tech = require("./server/tech/tech");
app.post("/tech/login", fb.validateFirebaseIdToken, tech.techLogin); app.post("/tech/login", fb.validateFirebaseIdToken, tech.techLogin);
var utils = require("./server/utils/utils"); const utils = require("./server/utils/utils");
app.post("/utils/time", utils.servertime); app.post("/utils/time", utils.servertime);
app.post("/utils/jsr", fb.validateFirebaseIdToken, utils.jsrAuth); app.post("/utils/jsr", fb.validateFirebaseIdToken, utils.jsrAuth);
var qbo = require("./server/accounting/qbo/qbo"); const qbo = require("./server/accounting/qbo/qbo");
app.post("/qbo/authorize", fb.validateFirebaseIdToken, qbo.authorize); app.post("/qbo/authorize", fb.validateFirebaseIdToken, qbo.authorize);
app.get("/qbo/callback", qbo.callback); app.get("/qbo/callback", qbo.callback);
app.post("/qbo/receivables", fb.validateFirebaseIdToken, qbo.receivables); app.post("/qbo/receivables", fb.validateFirebaseIdToken, qbo.receivables);
app.post("/qbo/payables", fb.validateFirebaseIdToken, qbo.payables); app.post("/qbo/payables", fb.validateFirebaseIdToken, qbo.payables);
app.post("/qbo/payments", fb.validateFirebaseIdToken, qbo.payments); app.post("/qbo/payments", fb.validateFirebaseIdToken, qbo.payments);
var data = require("./server/data/data"); const data = require("./server/data/data");
app.post("/data/ah", data.autohouse); app.post("/data/ah", data.autohouse);
app.post("/data/cc", data.claimscorp); app.post("/data/cc", data.claimscorp);
app.post("/data/kaizen", data.kaizen); app.post("/data/kaizen", data.kaizen);
app.post("/record-handler/arms", data.arms); app.post("/record-handler/arms", data.arms);
var taskHandler = require("./server/tasks/tasks"); const taskHandler = require("./server/tasks/tasks");
app.post("/taskHandler", fb.validateFirebaseIdToken, taskHandler.taskHandler); app.post("/taskHandler", fb.validateFirebaseIdToken, taskHandler.taskHandler);
var mixdataUpload = require("./server/mixdata/mixdata"); const mixdataUpload = require("./server/mixdata/mixdata");
app.post( app.post(
"/mixdata/upload", "/mixdata/upload",
fb.validateFirebaseIdToken, fb.validateFirebaseIdToken,
upload.any(), upload.any(),
mixdataUpload.mixdataUpload mixdataUpload.mixdataUpload
); );
var intellipay = require("./server/intellipay/intellipay"); const intellipay = require("./server/intellipay/intellipay");
app.post( app.post(
"/intellipay/lightbox_credentials", "/intellipay/lightbox_credentials",
fb.validateFirebaseIdToken, fb.validateFirebaseIdToken,
intellipay.lightbox_credentials intellipay.lightbox_credentials
); );
app.post( app.post(
"/intellipay/payment_refund", "/intellipay/payment_refund",
fb.validateFirebaseIdToken, fb.validateFirebaseIdToken,
intellipay.payment_refund intellipay.payment_refund
); );
app.post( app.post(
"/intellipay/generate_payment_url", "/intellipay/generate_payment_url",
fb.validateFirebaseIdToken, fb.validateFirebaseIdToken,
intellipay.generate_payment_url intellipay.generate_payment_url
); );
app.post( app.post(
"/intellipay/postback", "/intellipay/postback",
// fb.validateFirebaseIdToken, // fb.validateFirebaseIdToken,
intellipay.postback intellipay.postback
); );
var ioevent = require("./server/ioevent/ioevent"); const ioevent = require("./server/ioevent/ioevent");
app.post("/ioevent", ioevent.default); app.post("/ioevent", ioevent.default);
// app.post("/newlog", (req, res) => { // app.post("/newlog", (req, res) => {
// const { message, type, user, record, object } = req.body; // const { message, type, user, record, object } = req.body;
// logger.log(message, type, user, record, object); // logger.log(message, type, user, record, object);
// }); // });
var os = require("./server/opensearch/os-handler"); const os = require("./server/opensearch/os-handler");
app.post( app.post(
"/opensearch", //fb.validateFirebaseIdToken, "/opensearch", //fb.validateFirebaseIdToken,
os.handler os.handler
); );
app.post("/search", fb.validateFirebaseIdToken, os.search); app.post("/search", fb.validateFirebaseIdToken, os.search);
var cdkGetMake = require("./server/cdk/cdk-get-makes"); const cdkGetMake = require("./server/cdk/cdk-get-makes");
app.post("/cdk/getvehicles", fb.validateFirebaseIdToken, cdkGetMake.default); app.post("/cdk/getvehicles", fb.validateFirebaseIdToken, cdkGetMake.default);
app.get("/", async function (req, res) { app.get("/", async (req, res) => {
res.status(200).send("Access Forbidden."); res.status(200).send("Access Forbidden.");
}); });
server.listen(port, (error) => { server.listen(port, (error) => {
if (error) throw error; if (error) throw error;
logger.log( logger.log(
`[${process.env.NODE_ENV || "DEVELOPMENT"}] Server running on port ${port}`, `[${process.env.NODE_ENV || "DEVELOPMENT"}] Server running on port ${port}`,
"INFO", "INFO",
"api" "api"
); );
}); });

View File

@@ -0,0 +1,5 @@
const jobLifecycle = (req, res) => {
return res.status(200).send("jobLifecycle");
};
module.exports = jobLifecycle;

View File

@@ -3,3 +3,4 @@ exports.totalsSsu = require("./job-totals").totalsSsu;
exports.costing = require("./job-costing").JobCosting; exports.costing = require("./job-costing").JobCosting;
exports.costingmulti = require("./job-costing").JobCostingMulti; exports.costingmulti = require("./job-costing").JobCostingMulti;
exports.statustransition = require("./job-status-transition").statustransition; exports.statustransition = require("./job-status-transition").statustransition;
exports.lifecycle = require('./job-lifecycle');