-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
54 lines (46 loc) · 1.46 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
process.on("uncaughtException", (error) => {
console.log(error.name, error.message);
process.exit(1);
});
const express = require("express");
const cors = require("cors");
const crypto = require("crypto");
const mongoose = require("mongoose");
const cp = require("cookie-parser");
const dotenv = require("dotenv");
const errorhandlerfunc = require("./errors/errorhandlerfunc");
const errorclass = require("./errors/errorclass");
const authroute = require("./routers/authroute");
const tx_route = require("./routers/tx_route");
const { updateBalance } = require("./transactions/utils");
dotenv.config({ path: "./BitX.env" });
const app = express();
app.use(express.json());
const corsOPtion = {
origin: "http://localhost:3000/",
methods: ["GET", "PATCH", "POST", "DELETE"],
allowedHeaders: ["content-Type", "Autuorization"],
};
app.use(cors())
app.use(cp());
app.use("/auth", authroute);
app.use("/transaction", tx_route);
app.all("*", (req, res, next) => {
return next(new errorclass("wrong route"));
});
app.use(errorhandlerfunc);
mongoose
.connect(process.env.connect)
.then((err) => console.log("good👍"))
.catch((err) => console.log("bad👎"));
setInterval(updateBalance, 24 * 60 * 60 * 1000);
const port = process.env.PORT || 3000;
let applis = app.listen(port, () => {});
//console.log(new Date);
process.on("unhandledRejection", (error) => {
console.log(error.name, error.message);
applis.close(() => {
process.exit(1);
});
});
console.log();