OTM/server.js

36 lines
882 B
JavaScript
Raw Normal View History

2021-07-16 09:12:30 +02:00
const fastify = require('fastify')();//{ logger: true });
const path = require('path');
2023-06-14 15:06:57 +02:00
fastify.register(require('@fastify/static'), {
2021-07-16 09:12:30 +02:00
root: path.join(__dirname, 'public'),
prefix: '/public/',
2021-07-16 11:48:27 +02:00
});
2021-07-16 09:12:30 +02:00
2023-06-14 15:06:57 +02:00
fastify.register(require('@fastify/leveldb'), {
2021-07-16 09:12:30 +02:00
name: 'db'
}, err => {
if (err) throw err
});
2023-06-25 12:26:17 +02:00
fastify.register(require("@fastify/view"), {
engine: {
pug: require("pug"),
},
});
2021-07-16 09:12:30 +02:00
2021-07-16 12:02:23 +02:00
fastify.register(require('./router/api'), { prefix: '/api' });
2021-07-16 09:12:30 +02:00
2023-06-25 12:26:17 +02:00
fastify.get('/', (req, reply) => reply.view("/template/home.pug", ));
2021-07-16 09:12:30 +02:00
2023-06-25 12:26:17 +02:00
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-06-18 17:29:37 +02:00
fastify.listen({port:8080,host:'0.0.0.0'} ,(err,address) => {
2021-07-16 09:12:30 +02:00
if (err) throw err;
console.log("Listening on", address);
});