-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
31 lines (25 loc) · 889 Bytes
/
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
import express from "express";
import path from "path";
import { __dirname } from "./expose.js";
import listingRepo from "./repos/listing_repo.js";
import contactRepo from "./repos/contact_repo.js";
import { generateReports } from "./source/aggregations.js";
// Load the repositories
await listingRepo.load("../data/listings.csv");
await contactRepo.load("../data/contacts.csv");
const PORT = process.env.PORT || 3000;
const app = express();
app.use(express.json());
app.use(express.static(path.join(__dirname, "./public")));
app.set("view engine", "ejs");
app.get("/", (req, res) => {
const reports = generateReports(listingRepo, contactRepo);
res.render("index", { reports });
});
app.get("/api/reports", (req, res) => {
const reports = generateReports(listingRepo, contactRepo);
res.json(reports);
});
app.listen(PORT, () => {
console.log("Server is listening...");
});