-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
54 lines (48 loc) · 1.44 KB
/
index.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
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const dbConnect = require("./database/helpers/dbconnect");
const routes = require("./routes/index.js");
require("dotenv").config();
const app = express();
// middlewares
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(
cors({
origin: "*",
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
optionsSuccessStatus: 200,
})
);
routes.setupRoutes(app);
(async () => {
try {
await dbConnect().then(() => {
app.listen(process.env.PORT, () => {
console.log(`server listening on port ${process.env.PORT}`);
});
});
} catch (error) {
console.log(error);
}
})();
/**
* The block of code below is only used in development mode.
* It is used to forward webhooks from GitHub to the local server.
* This is necessary because the local server is not publicly accessible.
* The smee.io service is used to forward the webhooks.
* The smee.io target URL is the local server's URL.
* The smee.io source URL is the GitHub webhook URL.
* The smee.io service is started using the smee.start() method.
*
*/
const SmeeClient = require("smee-client");
if (process.env.NODE_ENV === "development") {
const smee = new SmeeClient({
source: `${process.env.SMEE_CLIENT_URL}`,
target: `http://localhost:${process.env.PORT}/api/event_badging`,
logger: console,
});
smee.start();
}