-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.mjs
More file actions
42 lines (32 loc) · 897 Bytes
/
server.mjs
File metadata and controls
42 lines (32 loc) · 897 Bytes
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
import map from "../basicExpress/map.json";
/* Empty JS object to act as endpoint for all routes */
const projectData = {};
/* Express to run server and routes */
import express from "express";
/* Start up an instance of app */
const app = express();
/* Dependencies */
import bodyParser from "body-parser";
/* Middleware*/
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
import cors from "cors";
app.use(cors());
/* Initialize the main project folder*/
app.use(express.static("website"));
const port = 3000;
/* Spin up the server*/
app.listen(port, listening);
function listening() {
// console.log(server);
console.log(`running on localhost: ${port}`);
}
// GET route
app.get("/all", sendData);
function sendData(request, response) {
response.send(projectData);
}
// GET all animals
app.get("/map", function (req, res) {
res.send(map);
});