-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
50 lines (36 loc) · 1.36 KB
/
server.ts
File metadata and controls
50 lines (36 loc) · 1.36 KB
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
import express from "express";
import mongoose from "mongoose";
import cors from "cors";
import { listenForTransfer } from "./utils/listeners/transferListener";
import { errorHandler } from "./middleware/errorHandler";
const { NODE_ENV } = process.env;
const path = NODE_ENV ? `.env.${NODE_ENV}` : ".env";
require("dotenv").config({ path });
const { DB_URL, PORT } = process.env;
console.log({ NODE_ENV, DB_URL });
// Routes
const products = require("./routes/products");
const transactions = require("./routes/transactions");
const deposits = require("./routes/deposits");
const listings = require("./routes/listings");
const arena = require("./routes/arena");
const app = express();
app.use(cors());
// Body parser
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
// Mount Routers
app.use("/api/v1/products", products);
app.use("/api/v1/transactions", transactions);
app.use("/api/v1/deposits", deposits);
app.use("/api/v1/listings", listings);
app.use("/api/v1/arena", arena);
// Handle cases where errors are thrown
app.use(errorHandler);
mongoose.connect(DB_URL || "mongodb://localhost:27017/thunderdome", {}, () => {
console.log("Connected to Mongo!");
});
// listeners
// Note: not super applicable given that using free service which will 'sleep'
// listenForTransfer();
app.listen(PORT, () => console.log(`Server up on Port: ${PORT}`));