-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
68 lines (57 loc) · 1.58 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 express, { Express } from "express";
import dotenv from "dotenv";
import cors from "cors";
import { router } from "./routes";
import bodyParser from "body-parser";
import cookieParser from "cookie-parser";
import https from "https";
import http from "http";
import fs from "fs";
import { handleSocket, initializeIoServer } from "./src/io/index";
import { setProd } from "./src/env";
dotenv.config();
const app: Express = express();
const port = process.env.PORT;
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use("/api", router);
app.use("/static", express.static("static"));
// whatsapp.client.initialize()
try {
const server = https.createServer(
{
key: fs.readFileSync(
"/etc/letsencrypt/live/app.agencyboz.com/privkey.pem",
"utf8"
),
cert: fs.readFileSync(
"/etc/letsencrypt/live/app.agencyboz.com/cert.pem",
"utf8"
),
ca: fs.readFileSync(
"/etc/letsencrypt/live/app.agencyboz.com/fullchain.pem",
"utf8"
),
},
app
);
const io = initializeIoServer(server);
io.on("connection", (socket) => {
handleSocket(socket);
});
server.listen(port, () => {
console.log(`[server]: Server is running at https://${port}`);
setProd();
});
} catch (e) {
const server = http.createServer(app);
const io = initializeIoServer(server);
io.on("connection", (socket) => {
handleSocket(socket);
});
server.listen(port, () => {
console.log(`[server]: Server is running at http://${port}`);
});
}