-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
68 lines (56 loc) · 1.55 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
import bodyParser from "body-parser";
import cors from "cors";
import errorhandler from "errorhandler";
import express, { Express, Request, Response } from "express";
import morgan from "morgan";
import {
ExampleVless,
inLocal,
isTestEnv,
needTelegramBot,
port,
} from "./config/constant";
import { getUriData, runTelegramBot } from "./controllers-bot/bot";
import { FetchInboundById } from "./controllers-bot/inbound";
import { getUriObject } from "./helper/helper";
const app: Express = express();
app.use(
cors({
origin: "*",
methods: ["GET", "POST"],
allowedHeaders: ["Content-Type"],
})
);
app.use(morgan("dev"));
app.use(bodyParser.json({ limit: "50mb", type: "application/json" }));
app.use(bodyParser.urlencoded({ limit: "50mb", extended: true }));
app.use(express.static(__dirname + "/public"));
if (isTestEnv) {
app.use(errorhandler());
}
app.get("/v", async (req: Request, res: Response) => {
const { uri } = req.query;
if (!uri || typeof uri !== "string") {
res.send("آدرس یافت نشد");
return;
}
let result = await FetchInboundById(uri);
res.send(result);
});
app.get("/t", async (req: Request, res: Response) => {
const { uri } = req.query;
if (typeof uri === "string") {
const r = await getUriData(uri);
res.send(r);
return;
}
res.send("آدرس سرور معتبر نمی باشد!");
});
if (needTelegramBot) {
runTelegramBot();
}
if (!needTelegramBot) {
app.listen(port, async function () {
console.log(`⚡️[server]: Server is running at http://localhost:${port}`);
});
}