-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
47 lines (37 loc) · 1.25 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
import * as bodyParser from "body-parser";
import * as express from "express";
import { Logger } from "./logger/logger";
import Routes from "./routes/routes";
const path = require('path');
class App {
public express: express.Application;
public logger: Logger;
// array to hold users
public users: any[];
constructor() {
this.express = express();
this.middleware();
this.routes();
this.users = [];
this.logger = new Logger();
}
// Configure Express middleware.
private middleware(): void {
this.express.use(bodyParser.json());
this.express.use(bodyParser.urlencoded({ extended: false }));
this.express.use(express.static(process.cwd() + "/bcard-admin-client-main/build/"));
}
private routes(): void {
// return client app on root request for url
this.express.get("/", (req, res, next) => {
res.sendFile(process.cwd() + "/bcard-admin-client-main/build/index.html");
});
// user route
this.express.use("/api", Routes);
// handle undefined routes
this.express.use("*", (req, res, next) => {
res.send("Make sure url is correct!!!");
});
}
}
export default new App().express;