-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
69 lines (60 loc) · 2.15 KB
/
index.ts
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import express, { Express } from "express";
import cors from "cors";
import dotenv from "dotenv";
import fileUpload from "express-fileupload";
import swaggerUi from "swagger-ui-express";
import YAML from "yamljs";
import bodyParser = require("body-parser");
import { InscriptionRouter } from "./src/routes/inscription.route";
import { StatusNetworkRoute } from "./src/routes/status.network.route";
import { WalletManageRoute } from "./src/routes/wallet.management.route";
import { EstimateFeeRouter } from "./src/routes/estimate.fee.route";
import { SendOrdinalRouter } from "./src/routes/send.ordinals.route";
import http from "http";
import { TESTNET } from "./src/config/network.config";
import { Mutex } from "async-mutex";
export const flagMutex = new Mutex();
export const iterator = new Mutex();
/*
* Load up and parse configuration details from
* the `.env` file to the `process.env`
* object of Node.js
*/
dotenv.config();
/*
* Create an Express application and get the
* value of the PORT environment variable
* from the `process.env`
*/
let swaggerDocument: any = "";
if (process.env.NETWORKTYPE == TESTNET) {
swaggerDocument = YAML.load("swagger_devnet.yaml");
} else {
swaggerDocument = YAML.load("swagger_mainnet.yaml");
}
export const app: Express = express();
app.locals.utxoflag = false;
const server = http.createServer(app);
const port = process.env.PORT || 8081;
app.use(fileUpload());
app.use(express.json({ limit: "50mb" }));
app.use(express.urlencoded({ limit: "50mb", extended: true }));
app.use(bodyParser.json({ limit: "50mb" }));
app.use(bodyParser.urlencoded({ limit: "50mb", extended: true }));
app.use(cors());
app.use("/api/inscribe", InscriptionRouter);
app.use("/api/estimate", EstimateFeeRouter);
app.use("/api/status", StatusNetworkRoute);
app.use("/api/wallet", WalletManageRoute);
app.use("/api/sendOrdinal", SendOrdinalRouter);
app.use(
"/api-docs",
swaggerUi.serve,
swaggerUi.setup(swaggerDocument, { explorer: true })
);
app.locals.iterator = 0;
/* Start the Express app and listen
for incoming requests on the specified port */
server.listen(port, () => {
console.log(`[server]: Server is running at http://localhost:${port}`);
});