OTM/server.js

36 lines
910 B
JavaScript
Raw Normal View History

2023-07-19 12:29:44 +02:00
const fastify = require("fastify")(); //{ logger: true });
const path = require("path");
2021-07-16 09:12:30 +02:00
2023-07-19 12:29:44 +02:00
fastify.register(require("@fastify/static"), {
root: path.join(__dirname, "public"),
prefix: "/public/",
2021-07-16 11:48:27 +02:00
});
2021-07-16 09:12:30 +02:00
2023-07-19 12:29:44 +02:00
fastify.register(
require("@fastify/leveldb"),
{
name: "db",
},
(err) => {
if (err) throw err;
2023-07-19 13:59:52 +02:00
}
2023-07-19 12:29:44 +02:00
);
2021-07-16 09:12:30 +02:00
2023-06-25 12:26:17 +02:00
fastify.register(require("@fastify/view"), {
2023-07-19 12:29:44 +02:00
engine: {
pug: require("pug"),
},
2023-06-25 12:26:17 +02:00
});
2021-07-16 09:12:30 +02:00
2023-07-19 12:29:44 +02:00
fastify.register(require("./router/api"), { prefix: "/api" });
2021-07-16 09:12:30 +02:00
2023-07-19 12:29:44 +02:00
fastify.get("/", (req, reply) => reply.view("/template/home.pug"));
fastify.get("/:id", (req, reply) => reply.view("/template/journey.pug"));
fastify.get("/view/:id", (req, reply) => reply.view("/template/view.pug"));
fastify.get("/short/:id", (req, reply) => reply.view("/template/short.pug"));
2021-07-16 09:12:30 +02:00
2023-07-19 12:29:44 +02:00
fastify.listen({ port: 8080, host: "0.0.0.0" }, (err, address) => {
if (err) throw err;
console.log("Listening on", address);
});