-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
49 lines (44 loc) · 1.32 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
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const db = require("./util/db");
const dotenv = require("dotenv");
dotenv.config();
const port = process.env.PORT || 3000;
// routes
const user = require("./routes/user");
const donation = require("./routes/donation");
const charity = require("./routes/charity");
const project = require("./routes/project");
const download = require("./routes/download");
const report = require("./routes/impactReport");
// models
const corsOptions = {
origin: ["http://localhost:3000"],
credentials: true,
method: ["GET", "POST", "PUT", "DELETE", "PATCH"],
allowedHeaders: ["Content-Type", "Authorization"],
};
// middleware
const app = express();
app.use(cors(corsOptions));
app.use(bodyParser.json());
app.use("/api/users", user);
app.use("/api/donations", donation);
app.use("/api/charities", charity);
app.use("/api/projects", project);
app.use("/api/", download);
app.use("/api/reports", report);
async function testConnection() {
try {
await db.authenticate();
console.log("Connection has been established successfully.");
await db.sync();
} catch (error) {
console.error("Unable to connect to the database:", error);
}
}
testConnection();
app.listen(port, () => {
console.log("Server started on port 3000");
});