-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
71 lines (59 loc) · 1.58 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
68
69
70
71
require("dotenv").config();
const Hapi = require("@hapi/hapi");
const { MailcowApiClient } = require("mailcow-api");
let tokens = {};
const mcc = new MailcowApiClient(
process.env.MAILCOW_API_BASEURL,
process.env.MAILCOW_API_KEY
);
exports.tokens = tokens
exports.mcc = mcc
const init = async() => {
const server = Hapi.server({
port: process.env.PORT || 3000,
host: "0.0.0.0",
routes: {
cors: {
origin: ["*"], // I should not have done this but I wanted this to production son badly
credentials: true
}
}
});
server.route({
method: "GET",
path: "/heartbeat",
handler: async(request, h) => {
return h
.response({ message: "up" })
.code(200)
.message('I am still alive');
},
});
server.route({
method: "POST",
path: "/auth",
handler: require('./handlers/auth').default,
});
server.route({
method: "POST",
path: "/account",
handler: require('./handlers/signUp').default,
});
server.route({
method: "GET",
path: "/account",
handler: require('./handlers/accountData').default,
});
server.route({
method: "PUT",
path: "/account",
handler: require('./handlers/changePassword').default,
});
await server.start();
console.log("Server running on %s", server.info.uri);
};
process.on("unhandledRejection", (err) => {
console.log(err);
process.exit(1);
});
init();