-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (30 loc) · 813 Bytes
/
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
const express = require("express");
const http = require("http");
const logger = require("morgan");
const bodyParser = require("body-parser");
const fn = require("./routingFunctions");
const app = express();
const port = 5000;
const server = http.createServer(app);
app.use(logger("dev"));
app.use(bodyParser.json());
app.get("/", fn.welcome);
app.get("/docs", fn.getDocs);
app.post("/doc", fn.postDoc);
app.get("/doc/:id", fn.getDocId);
app.put("/doc/:id", fn.putDoc);
app.delete("/doc/:id", fn.deleteDoc);
app.post("/doc/:id/event", fn.postEvent);
if (require.main == module) {
boot();
} else {
exports.boot = boot;
exports.shutdown = shutdown;
exports.port = port;
}
function boot() {
server.listen(port, () => console.log(`listening on ${port}`));
}
function shutdown() {
server.close();
}