-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartUp.ts
executable file
·63 lines (50 loc) · 1.38 KB
/
startUp.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
import * as express from "express";
import Database from "./infra/db";
import * as cors from "cors";
import * as compression from "compression";
import * as bodyParser from "body-parser";
import Auth from "./infra/auth";
import Uploads from "./infra/uploads";
import newsRouter from "./router/newsRouter";
class StartUp {
public app: express.Application;
private _db: Database;
private bodyParser;
constructor() {
this.app = express();
this._db = new Database();
this._db.createConnection();
this.middler();
this.routes();
}
enableCors() {
const options: cors.CorsOptions = {
methods: "GET, OPTIONS, PUT, POST, DELETE",
origin: "*"
};
this.app.use(cors(options));
}
middler() {
this.enableCors();
this.app.use(bodyParser.json());
this.app.use(bodyParser.urlencoded({ extended: false }));
this.app.use(compression());
this.app.use("/exports", express.static(process.cwd() + "/exports"));
}
routes() {
this.app.route("/").get((req, res) => {
res.send({ version: "0.0.1" });
});
this.app.route("/uploads").post(Uploads.single("file"), (req, res) => {
try {
res.send("file sent with sucess!");
} catch (error) {
console.log("error", error);
}
});
// this.app.use(Auth.validate);
//new
this.app.use("/", newsRouter);
}
}
export default new StartUp();