-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
71 lines (54 loc) · 1.67 KB
/
app.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
71
import * as express from "express";
import {Request, Response} from "express";
import * as logger from "morgan";
import * as path from "path";
import * as fs from "fs";
import * as cookieParser from "cookie-parser";
import {Middleware} from "./www/trivia";
import {Server} from "http";
import {log} from "./util/logger";
// -- Routes
import ApiV1 from "./api/v1/index";
import ApiV2 from "./api/v2/index";
import React from "./www/React";
// -- End Routes
import * as compression from "compression";
import {Mongoose} from "./middleware/Mongoose";
import SocketHandler from "./util/SocketHandler.new";
import GameInstanceManager from "./util/GameInstanceManager";
/**
*
* @type {Express}
*/
const app = express();
app.set("database", Mongoose());
app.use(logger("dev"));
app.use(compression());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.enable('trust proxy');
//log(path.join(process.cwd(), "./react/build"))
// app.use();
if (process.env.NODE_ENV && process.env.NODE_ENV.trim() === "production") {
app.use('/', React);
}
app.use('/api/v1', Middleware(), ApiV1);
app.use('/api/v2', ApiV2);
if (process.env.NODE_ENV && process.env.NODE_ENV.trim() === "production") {
if (process.env.PUBLIC_DIR) {
app.use(express.static(path.join(process.cwd(), `./${process.env.PUBLIC_DIR}/build`)));
}
if (process.env.PLAY_DIR) {
app.use(express.static(path.join(process.cwd(), `./${process.env.PLAY_DIR}/build`)));
}
}
// export function SocketInit(server:Server) {
// let x = SocketHandler(server);
//
// //console.log(x);
//
// }
GameInstanceManager.init();
SocketHandler.init();
export default app;