-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
33 lines (29 loc) · 942 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
const express = require("express");
const apiRouting = require("./routing/api.js");
const assistantRouting = require("./routing/assistant.js");
const routeLogger = require("./routing/logger.js");
const basicAuth = require("express-basic-auth");
const app = express();
const fs = require("fs");
const cors = require("cors");
// Load up the authorization file
const password = fs.readFileSync("password", "utf8").trim();
app.use(cors());
app.use(express.json());
if (password) {
const authMiddleware = basicAuth({
users: {
admin: password,
},
challenge: true,
});
app.use(`/api`, authMiddleware, apiRouting);
app.use(`/assistant`, authMiddleware, assistantRouting);
}
app.use(routeLogger); // Logs out to STDOUT with useful request info.
app.use(express.static("web"));
app.use(`/api`, apiRouting);
app.use(`/assistant`, assistantRouting);
app.listen(80, () => {
console.log(`Treadmill API now listening.`);
});