diff options
Diffstat (limited to 'index.js')
| -rw-r--r-- | index.js | 182 |
1 files changed, 72 insertions, 110 deletions
@@ -1,104 +1,79 @@ -import axios from 'axios'; -import bodyParser from 'body-parser'; -import compression from 'compression'; -import cookieParser from 'cookie-parser'; -import cors from 'cors'; -import express from 'express'; -import { Op } from 'sequelize'; -import persist from './lib/persist.js'; +import app from "./app.js"; +import axios from "axios"; +import bodyParser from "body-parser"; +import compression from "compression"; +import cookieParser from "cookie-parser"; +import cors from "cors"; +import express from "express"; +import { Op } from "@sequelize/core"; +import persist from "./lib/persist.js"; +import config from "./config/index.js"; +import { networks } from "./lib/store.js"; -ah = require("express-async-handler"); +// app = express(); +// app.enable("trust proxy"); +// app.use(bodyParser.urlencoded({ extended: true }); +// app.use(bodyParser.json()); +// +// app.use((err, req, res, next) => { +// const details = { +// path: req.path, +// body: req.body, +// msg: err.message, +// stack: err.stack +// }; +// +// if (req.user) details.username = req.user.username; +// +// l.error("JSON Error: ", JSON.stringify(details)); +// res.status(500); +// res.set({ +// "Cache-Control": "no-cache" +// }); +// res.send(err.message); +// return res.end(); +// }); +// app.use(cookieParser()); +// app.use(cors({ credentials: true, origin: "*" }); +// app.use(compression()); -config = require("./config"); -networks = []; -prod = process.env.NODE_ENV === "production"; -fail = msg => { - throw new Error(msg); -}; +import "./lib/logging.js"; +import "./lib/utils.js"; +import "./lib/sockets.js"; +import "./lib/webhooks.js"; +import "./lib/passport.js"; +import "./lib/register.js"; +import "./lib/upload.js"; +import "./lib/send.js"; +import "./lib/sync.js"; +import "./routes/assets.js"; +import "./routes/info.js"; +import "./routes/users.js"; +if (config.bitcoin) networks.push("bitcoin"); +if (config.liquid) networks.push("liquid"); +if (config.lna) networks.push("lightning"); -addresses = {}; -challenge = {}; -change = []; -exceptions = []; -issuances = {}; -logins = {}; -seen = []; -sessions = {}; -sockets = {}; -unaccounted = []; +import "./lib/rates.js"; +import "./lib/notifications.js"; -convert = persist("data/conversions.json"); +if (config.imap) import("./lib/mail.js"); +if (config.lnurl) import("./routes/lnurl.js"); +if (config.mailgun) import ("./routes/funding.js"); -SATS = 100000000; -toSats = n => Math.round(n * SATS); - -app = express(); -app.enable("trust proxy"); -app.use(bodyParser.urlencoded({ extended: true })); -app.use(bodyParser.json()); - -app.use((err, req, res, next) => { - const details = { - path: req.path, - body: req.body, - msg: err.message, - stack: err.stack - }; - - if (req.user) details.username = req.user.username; - - l.error("JSON Error: ", JSON.stringify(details)); - res.status(500); - res.set({ - "Cache-Control": "no-cache" - }); - res.send(err.message); - return res.end(); -}); -app.use(cookieParser()); -app.use(cors({ credentials: true, origin: "*" })); -app.use(compression()); - -server = require("http").Server(app); - -import './db/index.js'; -import './lib/logging.js'; -import './lib/utils.js'; -import './lib/sockets.js'; -import './lib/webhooks.js'; -import './lib/passport.js'; -import './lib/register.js'; -import './lib/upload.js'; -import './lib/send.js'; -import './lib/sync.js'; -import './routes/assets.js'; -import './routes/info.js'; -import './routes/users.js'; - if (config.bitcoin) networks.push("bitcoin"); - if (config.liquid) networks.push("liquid"); - if (config.lna) networks.push("lightning"); - - require("./lib/rates"); - require("./lib/notifications"); - - if (config.imap) require("./lib/mail"); - if (config.lnurl) require("./routes/lnurl"); - if (config.mailgun) require("./routes/funding"); - - require("./routes/invoices"); - require("./routes/payments"); - require("./routes/swaps"); +import "./routes/invoices.js"; +import "./routes/payments.js"; +// import "./routes/swaps.js"; // Scope based Route Handling -import referralsRouter from './routes/referrals.js'; +// import referralsRouter from './routes/referrals.js'; -app.use("/referrals", referralsRouter); +// app.use("/referrals", referralsRouter); -import adminRouter from './routes/admin.js'; -app.use("/admin", adminAuth, adminRouter); +// import adminRouter from './routes/admin.js'; +// app.use("/admin", adminAuth, adminRouter); -import './startup.js'; +import "./startup.js"; app.post("/email", async (req, res) => { try { @@ -132,28 +107,15 @@ app.post("/email", async (req, res) => { } }); -app.use((err, req, res, next) => { - const details = { - path: req.path, - body: req.body, - msg: err.message, - stack: err.stack - }; - - if (req.user) details.username = req.user.username; - - l.error("uncaught error: ", JSON.stringify(details)); - res.status(500); - res.set({ - "Cache-Control": "no-cache" - }); - res.send(err.message); +app.listen(process.env.PORT || 3119, "0.0.0.0", function(err, address) { + if (err) { + console.log(err); + app.log.error(err); + process.exit(1); + } + app.log.info(`CoinOS Server listening on ${address}`); }); -server.listen(config.port, () => - l.info(`CoinOS Server listening on port ${config.port}`) -); - process.on("SIGINT", process.exit); process.on("uncaughtException", function(exception) { |
