This repository has been archived by the owner on Sep 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
portalogic-server.ts
executable file
·70 lines (57 loc) · 1.89 KB
/
portalogic-server.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
70
import { createServer, Server } from "http";
import * as express from "express";
import * as socketIo from "socket.io";
import * as bodyParser from "body-parser";
import * as cors from "cors";
export class PortalogicServer {
public static readonly PORT: number = 8090;
private app: express.Application;
private server: Server;
private io: SocketIO.Server;
private port: string | number;
constructor() {
// create app
this.app = express();
this.app.use(cors());
this.app.use(bodyParser.json());
this.app.use(bodyParser.urlencoded({
extended: true
}));
// create server
this.port = process.env.PORT || PortalogicServer.PORT;
this.server = createServer(this.app);
// setup websockets
this.io = socketIo(this.server);
this.setup_routes();
this.listen();
}
private setup_routes(): void {
this.app.post("/send_email", function (req, res) {
let debug = false;
console.log("send_email");
});
}
private listen(): void {
this.server.listen(this.port, () => {
console.log("Running server on port %s", this.port);
});
this.io.on("connect", (socket: any) => {
console.log("Connected client on port %s.", this.port);
// setup event handles
socket.on("disconnect", (req: any) => {
console.log("Client disconnected");
});
socket.on("station_closed", (req: any) => {
console.log("station_closed");
this.io.emit("station_closed");
});
socket.on("station_open", (req: any) => {
console.log("station_open");
this.io.emit("station_open");
});
});
}
public getApp(): express.Application {
return this.app;
}
}