forked from MLH/mlh-localhost-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
37 lines (29 loc) · 1.11 KB
/
server.js
File metadata and controls
37 lines (29 loc) · 1.11 KB
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
require("dotenv").config();
const express = require("express");
const morgan = require("morgan");
const path = require("path");
const Addresses = require("./addresses");
const Locations = require("./locations");
const app = express();
const PORT = process.env.PORT || 3000;
const googleMapsApiKey = process.env.GOOGLE_API_KEY;
app.use("/static", express.static("static")); // Exposes static folder to serve images and styles
app.use(morgan("combined")); // Logs requests
app.set("view engine", "ejs"); // Set default view engine
const start = async function() {
// Let's load the addresses for the map.
const addresses = await Addresses.getAddresses();
// Let's convert these addresses into locations.
const locations = await Locations.getLocations(addresses);
// We need to define the basic route for our application.
app.get("/", function(req, res) {
res.render("index", { locations, apiKey: googleMapsApiKey });
});
// We start the application by listening to the defined PORT.
app.listen(PORT, function() {
console.log("Maps app listening on port " + PORT);
});
};
module.exports = {
start
};