-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (29 loc) · 854 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
const readLastLine = require("read-last-line");
const path = require("path");
const fastify = require("fastify")({});
const fastifyStatic = require("fastify-static");
const logLocation = path.join(process.env.HOME, "Private", "logs");
fastify.register(fastifyStatic, {
root: logLocation,
prefix: "/logs/",
prefixAvoidTrailingSlash: true,
list: {
format: "json",
names: ["index", "index.json", "/"],
},
});
// fastify.get("/logs", (request, reply) => {
// const filePath = path.join(__dirname, "log.txt");
// readLastLine
// .read(filePath, 200)
// .then(function (lines) {
// reply.send(lines);
// })
// .catch(function (err) {
// reply.send(filePath);
// });
// });
fastify.listen(3003, "0.0.0.0", (err, address) => {
if (err) throw err;
console.log(`server listening on ${address}`);
});