-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
67 lines (58 loc) · 1.51 KB
/
app.js
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
import fastify from "fastify";
import fastifyPlugin from "fastify-plugin";
import fastifyFormbody from "fastify-formbody";
import middie from "middie";
import nconf from "nconf";
import helmet from "fastify-helmet";
import { dbConnector } from "./config/db.js";
import { makeRoutes } from "./route/bonusRoutes.js";
class ApplicationESB {
constructor(input, flags) {
this.flags = flags;
this.input = input;
}
startServer() {
nconf.argv().env();
nconf.file({ file: "./config/server_config.json" });
nconf.defaults({
http: {
serverAddress: "localhost",
serverPort: 3000,
},
});
let app = fastify();
app.get("/", async () => {
return {
Message: "Welcome to 1С ESB",
};
});
app.addContentTypeParser(
"application/jsoff",
function (request, payload, done) {
jsoffParser(payload, function (err, body) {
done(err, body);
});
}
);
async function build() {
await app.register(middie);
await app.register(fastifyPlugin(dbConnector));
await app.register(helmet, { contentSecurityPolicy: false });
await app.register(fastifyFormbody);
return app;
}
build()
.then((app) => makeRoutes(app))
.then((app) => {
app.listen(
nconf.get("http:serverPort"),
nconf.get("http:serverAddress")
);
})
.catch((error) => {
console.log(error);
});
}
}
const runApp = new ApplicationESB();
runApp.startServer();